获取最新日期行

uubf1zoe  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(342)

doctrine2和mysql。。。
我想得到最新的一行数据。
infoaccount表

recordDate score   id
2018-10-10 99      A   // I need this row.
2018-10-9  88      B
2018-10-8  77      C

所以我用这个代码。

$query = $this->getEntityManager()->createQuery(
            'SELECT MAX(t.recordDate) 
            FROM App\Entity\InfoAccount t')

它只返回t.date的最大值。我想要整排。
它一定很简单,,,,,
感谢@scaisedge
----我是这样更新的。

'SELECT t 
FROM App\Entity\InfoAccount t
INNER JOIN (SELECT MAX(recordDate) 
as max_date FROM App\Entity\InfoAccount) k
ON t.max_date = k.recordDate '

但是它显示了错误 Error: Subquery is not supported here

4nkexdtk

4nkexdtk1#

您可以尝试在子查询中使用where日期

$query = $this->getEntityManager()->createQuery(
        ' select * from  App\Entity\Table m 
        where date in (
        SELECT MAX(t.date)  
        FROM App\Entity\Table )' 
        );

相关问题