62,046
社区成员
发帖
与我相关
我的任务
分享
select ComID from table_name a where not exists(select 1 from table_name where a.ComID=ComID and a.ListID<ListID) order by a.ComID desc
SELECT ComID FROM table_name
INNER JOIN (SELECT ComID,COUNT(ListID) AS cnt FROM table_name GROUP BY ComID) AS table_2
ON table_2.ComID=table_name.ComID
ORDER BY cnt
declare @tb table(ListID int,ComID int)
Insert @tb(ListID,ComID)
select 3 , 1 union all
select 8 , 2 union all
select 9 , 2 union all
select 10 , 4 union all
select 11 , 4 union all
select 12 , 4
select ComID from @tb group by ComID ORDER BY count(ComID) DESC