sql?where

WBOY
Release: 2016-06-20 12:43:43
Original
982 people have browsed it

根据当前时间来显示活动事件,越靠近当前时间的显示在最前面
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;
Copy after login
Copy after login
Copy after login

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;
Copy after login
Copy after login
Copy after login



[code=sql]SELECT * from 表名 where event_start_date<CURDATE() order by event_start_date desc;
只显示了<当前日期的,怎么和 >当前日期的拼成一个sql


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

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



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

不怕速度慢就用union吧
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!