张三  a  10
张三  b   5
李四  b   10
张三  a   20
李四  a   10
张三  b   5姓名  a   b
张三  30  10
李四  10   10linq

解决方案 »

  1.   

    因为姓名很多,table.Compute()的条件不知怎么处理好
      

  2.   

    这是标准的行转列,为什么不在sql中处理呢?
      

  3.   

    我在数据库建了一个表,大致实现了你想要的功能,可以参考一下中间那部分SUM的,你可以在程序里头用一个循环拼出来
      

  4.   

    group by '姓名' 类似这样
      

  5.   

    select uname, type, sum(num) from table group by uname, type
    (假设三列分别叫uname, type和num)
      

  6.   

    use Itcast2013
    select * from T_Score
    create table T_Csdn
    (
    name nvarchar(10) not null,
    ID char(2) not null,
    number int not null
    )
    insert into T_Csdn(name,ID,number)
    select N'张三','a',10 union all
    select N'张三','b',5 union all
    select N'张三','a',20 union all
    select N'李四','b',10 union all
    select N'李四','a',10 union all
    select N'张三','b',5 select 
    name as 姓名,
    sum((case ID  when 'a' then number   else 0  end)) as 'a' ,
    sum((case ID  when 'b' then number   else 0  end)) as 'b' 
    from T_Csdn
    group by name