GROUP BY having MAX date

后端 未结 4 1002
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 19:01

I have problem when executing this code:

SELECT * FROM tblpm n 
WHERE date_updated=(SELECT MAX(date_updated) 
FROM tblpm GROUP BY control_number 
HAVING cont         


        
4条回答
  •  无人及你
    2020-12-04 19:21

    There's no need to group in that subquery... a where clause would suffice:

    SELECT * FROM tblpm n
    WHERE date_updated=(SELECT MAX(date_updated)
        FROM tblpm WHERE control_number=n.control_number)
    

    Also, do you have an index on the 'date_updated' column? That would certainly help.

提交回复
热议问题