当我使用AS定义执行SELECT语句并且要对其进行过滤时,它会给出以下错误:#1054-“ where子句”中的未知列“ TimeInSeconds”

码:

Select Id, time/10000000 as TimeInSeconds FROM Results WHERE
TimeInSeconds > 5 AND
TimeInSeconds < 36000


我理解TimeInSeconds不是原始表的一部分的错误,但是有什么方法可以使用这些已定义的列?

最佳答案

您还可以使用HAVING子句过滤出自定义别名的结果

Select Id, `time`/10000000 as TimeInSeconds
FROM Results
HAVING TimeInSeconds > 5 AND TimeInSeconds < 36000


或使用WHERE子句重复表达式

Select Id, `time`/10000000 as TimeInSeconds
FROM Results
WHERE (`time`/10000000) > 5 AND (`time`/10000000) < 36000

10-08 18:02