我要总结的钱列,但我想在状态组名称和代码。
这是在存储的过程代码[SQL Server 2008中]:
SELECT um.upmoney as 'money'
,um.pId as 'code',um.FName as 'name',up.status as 'statusmoney'
From tb_upmoney um inner join tb_pID up on up.uId=um.pId
结果:
money | code | name | statusmoney
200.00 | 00001 | fin | 1
100.00 | 00001 | fin | 1
50.00 | 00001 | fin | 1
100.00 | 00002 | welson | 1
200.00 | 00002 | welson | 2
100.00 | 00002 | welson | 2
50.00 | 00002 | welson | 2
0.00 | 00002 | welson | 2
但我想要:
money | code | name | statusmoney
250.00 | 00001 | fin | 1
100.00 | 00002 | welson | 1
250.00 | 00002 | welson | 2
你需要SUM(UM.upmoney)
和基剩余场是这样的:
SELECT SUM(um.upmoney) AS 'money',
um.pId AS 'code',
um.FName AS 'name',
up.status AS 'statusmoney'
FROM tb_upmoney um
INNER JOIN tb_pID up
ON up.uId=um.pId
GROUP BY um.pId, um.FName, up.status
看到的示例GROUP BY子句与聚合器“SUM()”
SELECT sum(um.upmoney) as 'money',um.pId as 'code',um.FName as 'name',up.status as 'statusmoney'
From tb_upmoney um inner join tb_pID up on up.uId=um.pId group by um.pId, um.FName, up.status
怎么样
SELECT SUM(um.upmoney) as 'money',
um.pId as 'code',
um.FName as 'name',
up.status as 'statusmoney'
From tb_upmoney um inner join
tb_pID up on up.uId=um.pId
GROUP BY um.pId,
um.FName,
up.status
SUM(的Transact-SQL)
GROUP BY(的Transact-SQL)
检查此
SELECT SUM(um.upmoney)为 '钱',um.pId为 '代码',um.FName '姓名',up.status为 'statusmoney' 从tb_upmoney嗯内部联接tb_pID了上up.uId = um.pId GROUP BY um.FName,um.pId