假设我有这样一张桌子:
theme module changed
0 1 1426070691
1 1 1426070300
0 1 1324014321
1 2 1241245585
1 1 1015421251
我需要一个SQL查询,它返回相同的主题和模块的最大值更改:
theme module changed
0 1 1426070691
1 1 1426070300
1 2 1241245585
答案 0 :(得分:1)
您可以使用left join
select
t1.* from table_name t1
left join table_name t2
on t1.theme = t2.theme
and t1.module = t2.module
and t1.changed > t2.changed
where t2.theme is null
http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html
答案 1 :(得分:1)
您只需按theme
和module
SELECT theme, module, MAX(changed)
FROM table_name
GROUP BY theme, module