我有一张像......的桌子。
| id | name | meetingID | meeting_type | status | recurring_time | attendee_passwd | moderator_passwd | date_created | timezone | meeting_datetime | reminder | duration | created_by_id | sms_no | conferenceID | meeting_logout_url | max_participants | participants_id |
+----+------------------+-----------+--------------+--------+----------------+-----------------+------------------+---------------------+-----------+---------------------+----------+----------+---------------+--------+--------------+--------------------+------------------+-----------------+
| 7 | 6august | REG_524 | | NULL | | 90200 | 18614 | 0000-00-00 00:00:00 | GMT 5.45 | 2012-08-06 03:00:00 | 0 | 60 | 1 | 12356 | NULL | http://log.com | 20 | NULL |
我正在尝试按当前日期过滤表格,因此我使用以下查询
SELECT * from demo_meeting WHERE created_by_id IN(SELECT id FROM demo_user WHERE user_name = ' Sang') and meeting_datetime=curdate();
但我得到空集而不是得到结果。
请告诉我我在这里做错了什么
答案 0 :(得分:4)
您正在将日期时间与日期进行比较。
尝试将日期时间转换为日期,如下所示:
SELECT * from demo_meeting WHERE created_by_id IN ( SELECT id FROM demo_user WHERE user_name = ' Sang') AND DATE(meeting_datetime) = curdate();
答案 1 :(得分:1)
SELECT * from demo_meeting WHERE created_by_id IN(SELECT id FROM demo_user WHERE user_name = ' Sang') and DATE_FORMAT(meeting_datetime, '%Y-%m-%d')=curdate();
答案 2 :(得分:1)
尝试使用DATE( )
功能设置日期格式。顺便说一下,加入表格比SubQuery
更高效
SELECT a.*
FROM demo_meeting a
INNER JOIN demo_user b
ON a.created_by_id = b.ID
WHERE b.user_name = 'Sang' AND
DATE(a.meeting_datetime) = DATE(curdate())
答案 3 :(得分:0)
您正在将curdate()与字段meeting_datetime进行比较,该字段具有数据类型datetime / timestamp;你真正需要做的是比较日期(meeting_datetime)和curdate()。
查询将是:
SELECT * from demo_meeting WHERE created_by_id IN(SELECT id FROM demo_user WHERE user_name =' Sang')和date(meeting_datetime)=curdate();
希望它会帮助你。