【发布时间】:2014-11-12 21:54:09
【问题描述】:
如何将三个查询的结果合并到一个数据集中?交叉申请还是加入?
create table tbl_A
(
Dept varchar(5),
DocCountA int
);
create table tbl_b
(
Dept varchar(5),
DocCountB int
);
create table tbl_c
(
Dept varchar(5),
DocCountC int
);
insert into tbl_A
values ('XX',12),('YY',14),('ZZ',16)
insert into tbl_b
values ('XX',20),('YY',25),('ZZ',27)
insert into tbl_c
values ('XX',30),('YY',35)
select * from tbl_A
select * from tbl_B
select * from tbl_C
**tbl_A**
Dept DocCountA
XX 12
YY 14
ZZ 16
**tbl_B**
Dept DocCountB
XX 20
YY 25
ZZ 27
**tbl_C**
Dept DocCountC
XX 30
YY 35
结果
Dept DocCountA DocCountB DocCountC
XX
YY
ZZ
表 C 有两个结果 ZZ 将为空白
这需要使用两个查询 三个会很棒!
从 tbl_A A 中选择 *
交叉申请
(
从 tbl_b B 中选择 B.DocCountB
其中 B.Dept=A.Dept
) 草皮
【问题讨论】:
标签: sql cross-apply