我正在尝试将今天的日期与cur_date()
一起使用,并尝试将所有列拉到datestart
列和dateend
列之间。
我已经尝试了以下两种查询但得到:未知列' tdate'在' where子句'
SELECT id,
details,
CURDATE() AS tdate
FROM specials
WHERE tdate BETWEEN datestart AND dateend;
SELECT id,
details,
CURDATE() AS tdate
FROM specials WHERE datestart <= tdate AND dateend >= tdate;
答案 0 :(得分:2)
在WHERE子句中看不到此字段别名,请尝试此查询 -
SELECT
id, details, CURDATE() AS tdate FROM specials
WHERE
datestart <= CURDATE() AND dateend >= CURDATE();
或使用子查询 -
SELECT id, details, tdate FROM (
SELECT id, details, CURDATE() AS tdate FROM specials
) t
WHERE
datestart <= tdate AND dateend >= tdate;