我想根据select
子句更改where
值。是否可能以下任何方式?
SELECT b
FROM table
WHERE
IF date = '2016-03-24'
b = 1
ELSE IF date > date '2016-03-24' - 7 AND date < '2016-03-24'
b = 2
ELSE
b = 1
ORDER BY date
LIMIT 1
答案 0 :(得分:1)
使用CASE WHEN
:
SELECT CASE WHEN date = '2016-03-24' THEN 1
WHEN date > '2016-03-17' AND date < '2016-03-24' THEN 2
ELSE 1
END AS b
FROM table
ORDER BY b
LIMIT 1