在线 求一SQL 急! 有分
原表内容
字段 code data flag
1 20 A
2 40 B
1 30 B
2 20 A
3 10 B
3 20 A
查询得出:
字段: code data1 data2
1 20 30
2 40 20
3 10 20
flag为:A,B两中
一个code有两条数据data
大侠帮忙......
[解决办法]
select a.a,a.b,b.b from df a,df b where a.a=b.a and a.c= 'A ' and b.c= 'B '
[解决办法]
select distinct code,convert(integer,0)as data1,convert(integer,0) as data2 into table2 from table1;
-------------------------------
update table2
set data1=data from table1
where flag=A;
--------------------------
update table2
set data2=data from table1
where flag=B;