select 种类 from 表 group by 种类 order by count(*) desc
select 种类 from 表 group by 种类 order by count(*) desc
SELECT 种类 FROM 表名 GROUP BY 种类 ORDER BY COUNT(种类) DESC
select 种类,count(*) as Number from Phones group by 种类
select 种类,count(*) as Number from Phones group by 种类
select 种类,count(*) as Number from Phones group by 种类
來晚了,分被搶光了select 種類,count(產品) from table group by 種類
select 种类 from (select 种类,distinct 产品 FROM 表名) group by 种类 order by count(*) desc
--> Test Data: @T declare @T table ([种类] varchar(4),[产品] varchar(6)) insert into @T select '水果','苹果' union all select '水果','桔子' union all select '水果','梨' union all select '水果','荔枝' union all select '家具','桌子' union all select '家具','椅子' union all select '家具','床' union all select '家具','床' union all select '电脑','台式' union all select '电脑','笔记本'select * from @T --Code select [种类],COUNT(distinct [产品]) as 个数 from @T group by [种类] order by 个数 desc--Result /* 种类 个数 ---- ----------- 水果 4 家具 3 电脑 2 */
select 种类 ,count(*) from 表 group by 种类
select 种类,COUNT(distinct 产品) as 个数 from 表 group by 种类 order by 个数 desc
select 种类,count(*) as Number from Phones group by 种类
SELECT 种类
FROM 表名
GROUP BY 种类
ORDER BY COUNT(种类) DESC
declare @T table ([种类] varchar(4),[产品] varchar(6))
insert into @T
select '水果','苹果' union all
select '水果','桔子' union all
select '水果','梨' union all
select '水果','荔枝' union all
select '家具','桌子' union all
select '家具','椅子' union all
select '家具','床' union all
select '家具','床' union all
select '电脑','台式' union all
select '电脑','笔记本'select * from @T
--Code
select [种类],COUNT(distinct [产品]) as 个数 from @T
group by [种类] order by 个数 desc--Result
/*
种类 个数
---- -----------
水果 4
家具 3
电脑 2
*/
group by 种类 order by 个数 desc