请教一条sql语句?????
一张表A:
字段:机种(kind),销售金额(money)
电子类 100
电子类 200
机械类 300
家电类 400
家电类 500
日用品 700
机械类 900
如何得到结果:
机械类 1200
家电类 900
日用品 700
电子类 300
金额从高到低
------解决方案--------------------selct * from (select kind,sum(money)as countmony
from table group by kind) a
order by countmony
------解决方案--------------------select kind,sum([money]) as [money] from 表A group by kind order by [money] desc
------解决方案--------------------select kind,sum(money)as 金额合计
from 表A group by kind order by 金额合计
------解决方案--------------------select kind,sum(money)as 金额合计
from 表A group by kind order by 金额合计 desc
------解决方案--------------------declare @A table(kind varchar(10),[money] int)
insert into @A select '电子类 ',100
insert into @A select '电子类 ',200
insert into @A select '机械类 ',300
insert into @A select '家电类 ',400
insert into @A select '家电类 ',500
insert into @A select '日用品 ',700
insert into @A select '机械类 ',900
select kind,sum([money]) as [money] from @A group by kind order by [money] desc
/*
kind money
---------- -----------
机械类 1200
家电类 900
日用品 700
电子类 300
*/
------解决方案--------------------select kind ,sum(money) total from table group by kind order by total desc
------解决方案--------------------select kind,sum(money) as num from a
group by kind
order by num desc