求思路
张三 a 10张三 b 5
李四 b 10
张三 a 20
李四 a 10
张三 b 5
姓名 a b
张三 30 10
李四 10 10 linq --------------------编程问答-------------------- 希望能转换成第二个表的效果 --------------------编程问答-------------------- 因为姓名很多,table.Compute()的条件不知怎么处理好 --------------------编程问答-------------------- 用group by 不可以吗? --------------------编程问答-------------------- 这是标准的行转列,为什么不在sql中处理呢? --------------------编程问答-------------------- 我在数据库建了一个表,大致实现了你想要的功能,可以参考一下
中间那部分SUM的,你可以在程序里头用一个循环拼出来
--------------------编程问答-------------------- 眼神拙计。。。 --------------------编程问答-------------------- group by '姓名' 类似这样。。。 --------------------编程问答-------------------- select uname, type, sum(num) from table group by uname, type
(假设三列分别叫uname, type和num) --------------------编程问答--------------------
use Itcast2013--------------------编程问答-------------------- +1
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
补充:.NET技术 , C#