表客户
ID | Name | start_Date | Future
1 John 20-02-2014 15:00:00 0
2 Maria 20-02-2014 15:00:00 0
3 Stack 21-02-2014 15:00:00 1
4 Google 21-02-2014 15:00:00 0
目前,我的查询如下所示:
SELECT * FROM clients
显然这将获得所有客户端,但我想根据Future
变量显示客户端。设置Future
变量后,客户端只能从start_Date
进一步显示。
如果我将查询更改为:
SELECT *
FROM clients
WHERE (NOW() >= start_Date OR start_Date IS NULL
OR start_Date = '0000-00-00 00:00:00')
这会让我:
ID | Name | start_Date | Future
1 John 20-02-2014 15:00:00 0
2 Maria 20-02-2014 15:00:00 0
但我期望的输出是:
ID | Name | start_Date | Future
1 John 20-02-2014 15:00:00 0
2 Maria 20-02-2014 15:00:00 0
4 Google 21-02-2014 15:00:00 0
我不想展示
3 Stack 21-02-2014 15:00:00 1
因为变量Future
设置为1
,并且只能在明天(21-02-2014 15:00:00)显示。
所以,最后,我没有成功地提出这个问题:
SELECT *
FROM clients
WHERE CASE WHEN Future = 1 THEN (NOW() >= start_Date OR start_Date IS NULL
OR start_Date = '0000-00-00 00:00:00') END
答案 0 :(得分:2)
试试这个:
SELECT *
FROM clients
WHERE future = 0
OR (future = 1
AND (NOW() >= start_Date
OR start_Date IS NULL
OR start_Date = '0000-00-00 00:00:00'))
答案 1 :(得分:0)
为什么不使用这个
SELECT *
FROM clients
WHERE future = 0