[code]
select username,sum(hasmoney) from getone group by username
[/code]

解决方案 »

  1.   

    [code]
    select username,sum(hasmoney) from getone group by username
    [/code]
      

  2.   

    select username,sum(hasmoney) from  getone group by username
      

  3.   

    create table getone( 
    uid int identity(1,1), 
    username varchar(16), 
    hasmoney int 
    ) insert into getone(username,hasmoney)values('张三',10) 
    insert into getone(username,hasmoney)values('李四',20) 
    insert into getone(username,hasmoney)values('李四',20) 
    insert into getone(username,hasmoney)values('王五',30) 
    insert into getone(username,hasmoney)values('王五',30) 
    insert into getone(username,hasmoney)values('飞机',30) 
    select username,hasmoney from 
    (select * from getone a where not exists(select 1 from getone where username=a.username and uid<a.uid)
     union all 
    select 99,'总计',sum(hasmoney) from getone a where not exists(select 1 from getone where username=a.username and uid<a.uid)) t
    order by uidusername         hasmoney
    ---------------- -----------
    张三               10
    李四               20
    王五               30
    飞机               30
    总计               90(5 行受影响)