Mysql选择应该有今天和明天日期的记录 [英] Mysql select record that should have today and tomorrow date

查看:54
本文介绍了Mysql选择应该有今天和明天日期的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择必须有两个或更多条目但在表中应该有今天和明天日期的记录.我正在以日期格式在表格中保存日期.

I want to select record that must have two or more entries but should have today and tomorrow date in table. I am saving date in table in date format.

SELECT `availibility`.* 
FROM (`availibility`) 
WHERE `property_id`= 8818 
AND (availibility.unavailibility_date between CURDATE() 
AND DATE_ADD(CURDATE(),INTERVAL 1 DAY))

我正在使用上面的查询,但即使存在某个日期(今天或明天)也会如此.我想得到这样的记录,应该有两个日期例如

I am using above query but this will true even one date (today or tomorrow) exists. I want to get such record that should have both dates for example

+---------+----------------+------------+
|   ID    |   property_id  |  Date      |
+---------+----------------+------------+
| 369516  | 8818           | 2013-01-19 |
| 369517  | 8818           | 2013-01-18 |
| 369518  | 8818           | 2013-01-17 |
| 418021  | 8818           | 2013-08-27 |
| 418022  | 8818           | 2013-08-28 |
| 418022  | 8818           | 2013-08-29 |
| 418022  | 2001           | 2013-07-29 |
| 418022  | 2001           |2013-07-30  |
+---------+----------------+------------+

8818 属性应该出现在记录集中,因为这里存在两个日期

8818 property should come in record set because both date exists here

推荐答案

SELECT property_id
FROM yourtable
WHERE date IN (CURDATE(), CURDATE() + INTERVAL 1 DAY)
GROUP BY property_id
HAVING COUNT(DISTINCT date)=2

请参阅 fiddle 此处.

Please see fiddle here.

这篇关于Mysql选择应该有今天和明天日期的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆