您好我已经创建了一个包含以下字段的事件表:
我希望有一个查询可以显示已启动但尚未完成的事件,另一个查询则显示尚未启动的事件。
答案 0 :(得分:0)
假设数据字段是空字符串,直到它们被设置为止:
select * from events where start-date!='' and end-date='';
select * from events where start-date='';
答案 1 :(得分:0)
如果我理解了您想要达到的目标,并假设startdate
和enddate
类型为DATETIME
,那么您可以
-- started but not finished
SELECT *
FROM events
WHERE startdate <= NOW()
AND enddate > NOW();
示例输出(当前日期/时间为March, 06 2014 16:28:26+0000
):
| ID | TITLE | STARTDATE | ENDDATE | VENUE | |----|--------|------------------------------|------------------------------|--------| | 2 | Event2 | March, 04 2014 16:22:55+0000 | March, 08 2014 16:22:55+0000 | Venue2 |
-- not started yet
SELECT *
FROM events
WHERE startdate > NOW();
示例输出(当前日期/时间为March, 06 2014 16:28:26+0000
):
| ID | TITLE | STARTDATE | ENDDATE | VENUE | |----|--------|------------------------------|------------------------------|--------| | 3 | Event3 | March, 08 2014 16:22:55+0000 | March, 11 2014 16:22:55+0000 | Venue3 |
这是 SQLFiddle 演示