在子查询中使用 subdate 和 max(date)
Using subdate and max(date) in a subquery
我尝试了这个查询,但遇到了错误。子查询单独returns想要的结果。
Select *
from usi
where present_date = select subdate(MAX(present_date), 1) AS PreviousDate from usi
我做错了什么?
您需要在子查询周围加上括号:
Select *
from usi
where present_date = (select subdate(MAX(present_date), 1) AS PreviousDate from usi);
注意:subdate()
——虽然完全有效——看起来很奇怪。我更习惯看到 date_sub()
或 - interval 1 day
.
我尝试了这个查询,但遇到了错误。子查询单独returns想要的结果。
Select *
from usi
where present_date = select subdate(MAX(present_date), 1) AS PreviousDate from usi
我做错了什么?
您需要在子查询周围加上括号:
Select *
from usi
where present_date = (select subdate(MAX(present_date), 1) AS PreviousDate from usi);
注意:subdate()
——虽然完全有效——看起来很奇怪。我更习惯看到 date_sub()
或 - interval 1 day
.