嗨,我有一个数据库,我使用此查询获取使用group by和order by的最新记录 我已经使用此代码获取所有记录
SELECT id,time FROM eventlog WHERE event = '2' ORDER BY `eventlog`.`id` DESC
我得到了这个输出:
我想得到每个小组的最新时间 我已将此查询用于按查询顺序分组
SELECT id,time FROM eventlog WHERE event = '2' GROUP BY id ORDER BY time DESC
答案 0 :(得分:4)
试试这个:
SELECT id,MAX(`time`) as `time` FROM eventlog WHERE event = '2' GROUP BY id DESC