select [ID], 姓名 ,pTotal as '扣钱(元)' from (select [id], sum(扣钱) as pTotal from tabc group by [ID]) C,tabcwhere C.[id]= tabc.[id]
try this select rownum ID,(select 姓名,sum(扣钱) from tabc group by 姓名) 你的姓名对应多个Id,这里的id不是你以前表里的
select (select top 1 ID from 姓名=a. 姓名 order by id),姓名,sum(扣钱(元)) from tab a group by 姓名应该不会错了
刚才那个不对,try thisif object_id('tempdb..#temp') is not null drop table #temp select identity(int,1,1) as 编号,select 姓名,sum(扣钱) as 扣钱 into #temp from tabc group by 姓名 select * from #temp
select left(姓名,1) as xm,sum(扣钱) from tabc group by 姓名
select min(id),name,sum(money) from table group by name order by min(id)
这算少了,嘿,大哥啊,这不是我说了算啊,都是那boss
你那个结果集中的ID到底有没有意义? 如果没有,可以试着这样 select min(ID) as ID,姓名,sum(isnull(扣钱(元),0)) as 扣钱(元) from
sorry你那个结果集中的ID到底有没有意义?如果没有,可以试着这样 select min(ID) as ID,姓名,sum(isnull([扣钱(元)],0)) as [扣钱(元)] from Tabc group by 姓名
可以 Group By 多个字段: select ID, 姓名, sum(扣钱) from TableName group by ID, 姓名
from
(select [id], sum(扣钱) as pTotal from tabc group by [ID]) C,tabcwhere C.[id]= tabc.[id]
select rownum ID,(select 姓名,sum(扣钱) from tabc group by 姓名)
你的姓名对应多个Id,这里的id不是你以前表里的
select (select top 1 ID from 姓名=a. 姓名 order by id),姓名,sum(扣钱(元))
from tab a
group by 姓名应该不会错了
drop table #temp
select identity(int,1,1) as 编号,select 姓名,sum(扣钱) as 扣钱 into #temp from tabc group by 姓名
select * from #temp
from tabc
group by 姓名
from table
group by name
order by min(id)
如果没有,可以试着这样
select min(ID) as ID,姓名,sum(isnull(扣钱(元),0)) as 扣钱(元)
from
select min(ID) as ID,姓名,sum(isnull([扣钱(元)],0)) as [扣钱(元)]
from Tabc
group by 姓名
select ID, 姓名, sum(扣钱) from TableName group by ID, 姓名