由买买提看人间百态

topics

全部话题 - 话题: columnc1
(共0页)
B*****g
发帖数: 34098
1
来自主题: Database版 - SQL Server query 一问
SELECT a.id1, a.id2, d.ColumnB1, d.ColumnB2, d.ColumnC1, d.ColumnC2
FROM A a,
(SELECT b.id1, b.id2, b.ColumnB1, b.ColumnB2, NULL ColumnC1, NULL ColumnC2
FROM B b
UNION ALL
SELECT c.id1, c.id2, NULL ColumnB1, NULL ColumnB2, ColumnC1, ColumnC2
FROM C c
) d
WHERE a.id1 = d.id2
AND a.id2 = d.id2
d*h
发帖数: 2347
2
来自主题: Database版 - SQL Server query 一问
select A.id1, A.id2, B.ColumnB1 ColumnB1, B.ColumnB2 ColumnB2, NULL as
ColumnC1, NULL as ColumnC2
from table1 A
right join table2 B
on A.id1=B.id1
and A.id2=B.id2
union all
select A.id1, A.id2, NULL as ColumnB1, NULL as ColumnB2, C.ColumnC1 ColumnC1
, C.ColumnC2 ColumnC2
from table1 A
right join table3 C
on A.id1=C.id1
and A.id2=C.id2;
d*h
发帖数: 2347
3
来自主题: Database版 - SQL Server query 一问
select A.id1, A.id2, B.ColumnB1 ColumnB1, B.ColumnB2 ColumnB2, NULL as
ColumnC1, NULL as ColumnC2
from A
right join B
on A.id1=B.id1
and A.id2=B.id2
union all
select A.id1, A.id2, NULL as ColumnB1, NULL as ColumnB2, C.ColumnC1 ColumnC1
, C.ColumnC2 ColumnC2
from A
right join C
on A.id1=C.id1
and A.id2=C.id2;
B*****g
发帖数: 34098
4
来自主题: Database版 - SQL Server query 一问
SELECT a.id1, a.id2, b.ColumnB1, b.ColumnB2, NULL ColumnC1, NULL ColumnC2
FROM A a, B b
WHERE a.id1 = b.id2
AND a.id2 = b.id2
UNION ALL
SELECT a.id1, a.id2, NULL ColumnB1, NULL ColumnB2, ColumnC1, ColumnC2
FROM A a, C c
WHERE a.id1 = c.id2
AND a.id2 = c.id2
有包子吗?
n********6
发帖数: 1511
5
来自主题: Database版 - SQL Server query 一问
我的土办法,不知是否可行。
1。把id1, id2连起来,变成id3。
2。
SELECT A.ID3, B.ColumnB1, B.ColumnB2, C.ColumnC1, C.ColumnC2
FROM A LEFT JOIN B ON A.ID3 = B.ID3
RIGHT JOIN C ON A.ID3 = B.ID3
细节和优化方案正在思索中。
(共0页)