重复记录并和
表 A
姓名 衣服 裤子 鞋 金额
a 1 11
a 1 89
a 1 67
表 B
姓名 衣服 裤子 鞋 总金额
a 11 89 67 167
请教,怎么用SQL 语句吧表A转换成表B啊?????
[解决办法]
create table 表A(姓名 varchar(10),衣服 INT,裤子 INT,鞋 INT,金额 INT)insert into 表A select 'a',1,null,null,11insert into 表A select 'a',null,1,null,89insert into 表A select 'a',null,null,1,67goselect 姓名,sum(case when 衣服 is not null then 金额 else 0 end)as 衣服,sum(case when 裤子 is not null then 金额 else 0 end)as 裤子,sum(case when 鞋 is not null then 金额 else 0 end)as 鞋,sum(金额)as 总金额from 表Agroup by 姓名/*姓名 衣服 裤子 鞋 总金额---------- ----------- ----------- ----------- -----------a 11 89 67 167(1 行受影响)*/godrop table 表A