【发布时间】:2015-05-20 03:53:05
【问题描述】:
我的表中有类似以下的数据:
id territory_id platform_id title_id other columns
1 US ITUNES 155 10 others columns...
100 US ITUNES 155 10 others columns...
101 FR ITUNES 155 10 others columns...
我需要在所有重复行上使用SELECT MAX(ID),基于(territory_id, platform_id, title_id)。
对上述数据集的查询应返回 id 100,因为上面基于 (territory_id, platform_id, title_id) 的唯一重复项是 ('US', 'ITUNES', 155),而该重复项的 MAX(ID) 是 100(不是 1 )。
我将如何构建此查询?到目前为止,我有:
SELECT id FROM table GROUP BY territory_id, platform_id, title_id
【问题讨论】:
-
SELECT territory_id, platform_id,title_id,MAX(id) FROM my_table GROUP BY territory_id, platform_id,title_id; -
这是一个重复的问题,我找不到。
标签: mysql