(SELECT dtable.*, new_apps.top as t1 FROM app_detailsvvv as dtable INNER JOIN new_apps ON
new_apps.trackId=dtable.trackId WHERE (SELECT COUNT(*) AS c FROM compositions as dtablev
WHERE parent='169469' AND trackId=dtable.trackId AND new_apps.top > 0)>0) UNION
(SELECT *, 301 FROM app_detailsvvv as dtable WHERE (SELECT COUNT(*) AS c FROM compositions
as dtablev WHERE parent='169469' AND trackId=dtable.trackId)>0) ORDER BY t1 ASC, trackName
ASC LIMIT 0,12
这个查询给我带来了重复,我怎么可以通过trackId分组?
最佳答案
将trackid作为SELECT语句的一部分...
SELECT new_apps.trackId,
..etc...
..
..
GROUP BY 1
确保其余的SELECT项(包括子SQL查询)已经聚合-例如MAX,FIRST,SUM或将它们分组为单个结果的内容。