有3条语句:
select A as 列1 from Tab where 条件1;
select A as 列2 from Tab where 条件2;
select A as 列3 from Tab where 条件3;
怎样把这3个列放到一个结果呢?列1
a
b列2
c
d
e列3
e
f需要的结果是:
列1 列2 列3
a c e
b d f
(null) e (null)
select A as 列1 from Tab where 条件1;
select A as 列2 from Tab where 条件2;
select A as 列3 from Tab where 条件3;
怎样把这3个列放到一个结果呢?列1
a
b列2
c
d
e列3
e
f需要的结果是:
列1 列2 列3
a c e
b d f
(null) e (null)
创造关联条件吧
2005 row_number
2000 临时表自增列
需要的结果是:
列1 列2 列3
a c e
b d f
(null) e (null)
二楼,可以给出详细点的方法吗 谢谢
a c e
b d f
(null) e (null)
select id=identity(int,1,1),* into #a from b
select id=identity(int,1,1),* into #a from c
select
a.列1,b.列2,c.列3
from
#a a left join #b b on a.id=b.id left join #c c on a.id=c.id
当然条件1 对 a ,条件2对b,条件3对c