首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一SQL语句的写法!解决马上给分!该怎么处理

2012-01-22 
求一SQL语句的写法!解决马上给分!有一表结构如下:totalmoneycusterNum109.75k00345k00376k004430k005107k0

求一SQL语句的写法!解决马上给分!
有一表结构如下:

totalmoney       custerNum
109.75               k003
45                       k003
76                       k004
430                     k005
107                     k006
43                       k007
98                       k006
...
....
--------------------
求一条语句即可算出每个custerNum的sum(totalmoney)的总额,即每个客户的购物总额!谢谢.本人较菜

[解决办法]
select custerNum,sum(totalmoney)
from 表
group by custerNum
[解决办法]
select sum(totalmoney) 总额,custerNum from tb group by custerNum
--group by 起汇总作用,即当custerNum时计算所有字段为custerNum的totalmoney和
或用
--
select totalmoney,custerNum,总额=(select sum(totalmoney) from tb where custerNum=a.custerNum) from tb a
[解决办法]
按 custerNum  分组
[解决办法]
select sum(totalmoney) as 总额,custerNum from tb group by custerNum
--group by 起汇总作用,即当custerNum时计算所有字段为custerNum的totalmoney和
或用
--
select custerNum,总额=sum(totalmoney) from tb group by custerNum
[解决办法]
create table t(
totalmoney decimal(10,2),
custerNum varchar(10)
)
insert into t select 109.75 , 'k003 '
union all select 45 , 'k003 '
union all select 76 , 'k004 '
union all select 430 , 'k005 '
union all select 107 , 'k006 '
union all select 43 , 'k007 '
union all select 98 , 'k006 '

select custerNum,sum(totalmoney)as totalmoney
from t
group by custerNum

drop table t
--------------------
k003154.75
k00476.00
k005430.00
k006205.00
k00743.00

[解决办法]
select custerNum,sum(totalmoney) as 购物总额
from 表
group by custerNum
[解决办法]
select custerNum,sum(totalmoney) as 购物总额
from 表
group by custerNum
order by custerNum
[解决办法]
都是对的,不说了
[解决办法]


select * from T
order by custerNum
compute sum(totalmoney)as totalmoney by custerNum
compute sum(totalmoney)as totalmoney2

热点排行