Heim  >  Artikel  >  Backend-Entwicklung  >  sql?where

sql?where

WBOY
WBOYOriginal
2016-06-20 12:43:43955Durchsuche

根据当前时间来显示活动事件,越靠近当前时间的显示在最前面
1.当前时间为 2015-11-25,则显示顺序
2015-11-25,    2015-11-26,    2015-12-27,   2015-01-20,     2014-11-24
2.当前时间为 2015-12-01,则显示顺序
2015-12-27,    2015-11-25,    2015-11-26,    2015-01-20,     2014-11-24
3.当前时间为 2015-12-30,则显示顺序
2015-12-27,    2015-11-25,    2015-11-26,     2015-01-20,    2014-11-24

这个where语句要怎么写


回复讨论(解决方案)

这年头伸手党真多,拿去玩吧

SELECT * from 表名 where event_start_date<CURDATE() order by event_start_date desc;

2.当前时间为 2015-12-01,则显示顺序
2015-12-27,    2015-11-25,    2015-11-26,    2015-01-20,     2014-11-24

2015-12-27 距 2015-12-01 26天
2015-11-25 距 2015-12-01 5天
为何 2015-12-27 要排在前面?
不是与 越靠近当前时间的显示在最前面 的条件相佐吗

2.当前时间为 2015-12-01,则显示顺序
2015-12-27,    2015-11-25,    2015-11-26,    2015-01-20,     2014-11-24

2015-12-27 距 2015-12-01 26天
2015-11-25 距 2015-12-01 5天
为何 2015-12-27 要排在前面?
不是与 越靠近当前时间的显示在最前面 的条件相佐吗



当前时间为 2015-12-01时,活动2015-11-25已过去
应该说成:越靠近当前时间的显示在最前面 并且开始日期>=当前日期

这年头伸手党真多,拿去玩吧

SELECT * from 表名 where event_start_date<CURDATE() order by event_start_date desc;



[code=sql]SELECT * from 表名 where event_start_date只显示了当前日期的拼成一个sql


这年头伸手党真多,拿去玩吧

SELECT * from 表名 where event_start_date<CURDATE() order by event_start_date desc;



[code=sql]SELECT * from 表名 where event_start_date只显示了当前日期的拼成一个sql

不怕速度慢就用union吧
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn