下面是我写的查询
SELECT *, YEAR(CURDATE()) - YEAR(age) AS age FROM table1
并且我想操作以上查询中的“年龄”列
例如:
SELECT * FROM table1 WHERE age BETWEEN 1 AND 9
如何从此查询中完成
SELECT *, YEAR(CURDATE()) - YEAR(age) AS age FROM table1
我的结果将返回包含年龄范围的行
答案 0 :(得分:0)
您可以像使用
一样将query
用作subquery
SELECT t2.* FROM
( SELECT t1.*, YEAR(CURDATE()) - YEAR(age) AS age FROM table1 t1 ) t2
WHERE t2.age BETWEEN 1 and 9
答案 1 :(得分:0)
MySQL为 g++ -Ic:\ProgramData\Anaconda3\include -Lc:\ProgramData\Anaconda3\libs test.cpp
子句提供了扩展,允许您执行所需的操作:
HAVING
注意:我假设您想要某种年份的 date 列。花一年的时间称为SELECT *, YEAR(CURDATE()) - YEAR(date) AS age
FROM table1
HAVING age BETWEEN 1 AND 9;
并没有任何意义。