SQL 复杂问题求解?
现在有一张表:
按进口日期查询: FROM DATE: 2007-01-01 TO DATE: 2007-04-01
结果为:
公司名 出口 进口
A 100 150
B 200 50
C 150 150
D 380 650
E 260 450
F 180 70
现在要求:同样按进口日期查询: FROM DATE: 2007-01-01 TO DATE: 2007-04-01
显示的结果为:
公司名 一月出口 一月进口 二月出口 二月进口 三月出口 三月出口
A 10 50 60 70 30 30
B 100 20 30 10 70 20
C 50 10 30 100 70 40
D 180 350 120 150 80 150
E 60 150 150 230 50 70
F 80 20 60 10 40 40
该怎么做呢?如果有什么地方不清楚可以联系我?谢谢了
------解决方案--------------------create table temp49(id varchar(10),import int ,export int,cdate datetime)
insert into temp49
select 'A ',10,50, '2007-04-01 '
union all select 'A ',60,70, '2007-02-01 '
union all select 'A ',30,30, '2007-03-01 '
union all select 'B ',100,20, '2007-01-01 '
union all select 'B ',30,100, '2007-02-01 '
union all select 'B ',70,20, '2007-03-01 '
union all select 'C ',50,10, '2007-01-01 '
union all select 'C ',30,100, '2007-02-01 '
union all select 'C ',70,40, '2007-03-01 '
union all select 'D ',180,350, '2007-01-01 '
union all select 'D ',120,150, '2007-02-01 '
union all select 'D ',80,150, '2007-03-01 '
union all select 'E ',60,150, '2007-01-01 '
union all select 'E ',150,230, '2007-02-01 '
union all