scheduled_datetime
2016-12-07 10:30:00
2016-12-07 13:30:00
2016-11-06 22:30:00
2016-12-06 23:30:00
2016-19-08 22:30:00
如果日期相同则按日期排序第一个日期
select *
from mytable
where scheduled_datetime > now()
order by scheduled_datetime;
从这个查询我必须找到比今天更大的日期,请告诉我哪里出错了。
答案 0 :(得分:0)
您有以下3个选项:
--If you want to fetch records greater than current date & time
select * from mytable where scheduled_datetime > NOW()
--If you want to fetch records greater than current date
select * from mytable where scheduled_datetime > CURDATE()
--If you want to fetch records greater than current time
select * from mytable where scheduled_datetime > CURTIME()
您可以根据您想要获取数据的顺序使用ORDER BY ASC或DESC。
答案 1 :(得分:0)
如果您只想输出大于今天的日期,则需要使用DATE()
仅与scheduled_datetime
的日期值进行比较:
select *
from mytable
where DATE(scheduled_datetime) > NOW()
order by scheduled_datetime asc;