select songid,CategoryID,count(*) from sod_artist_category_relation group by songid;
他除了正常的分组,还可以带上其他的字段,如果这些额外的字段有重复,则选择第一个数据。
这个特性很方便,如果使用Oracle,可以使用相关子查询模拟,
select songid,
(select min(CategoryID) from sod_artist_category_relation where songid=t1.songid) CategoryID,count(*) from sod_artist_category_relation t1 group by songid;本文永久更新链接地址