0

我正在尝试使用今天的日期cur_date()并尝试将所有列拉到datestart列和dateend列之间。

我已经尝试了以下两个查询,但得到:'where 子句'中的未知列'tdate'

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;
4

1 回答 1

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;
于 2012-12-10T07:49:30.470 回答