Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在子查询中使用子日期和最大(日期)_Mysql_Date_Subquery_Aggregate Functions - Fatal编程技术网

Mysql 在子查询中使用子日期和最大(日期)

Mysql 在子查询中使用子日期和最大(日期),mysql,date,subquery,aggregate-functions,Mysql,Date,Subquery,Aggregate Functions,我尝试了这个查询,但出现了错误。子查询单独返回所需的结果 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 fr

我尝试了这个查询,但出现了错误。子查询单独返回所需的结果

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\u sub()
-间隔1天

谢谢戈登。您的解决方案未给出错误,但未按预期检索任何记录。日期和间隔1天都给出了错误。我不知道为什么,现在这是维德。我一直在做我当地的phpmyadmin。我刚试过你的现场提问(phpmyadmin版本3.5.8.2,它工作得很好,而本地phpmyadmin版本4.4.14仍然没有检索到行。会发生什么事?@Gyne…我猜两个系统的数据是不同的。即使数据看起来相同,你也需要小心,因为
present\u date
可能有一个时间组件。谢谢戈登.我放弃了我的本地表,导入了产品。现在一切正常,包括DATE\u SUB(MAX(present\u DATE),间隔1天