S
seeme0526
Unregistered / Unconfirmed
GUEST, unregistred user!
我有两个表A 和 B,想把它们的数据合并,结构如下:(*为主键)
A:cl_bm char(7) *
cl_dw char(7) *
cl_kc dec(9,3)
---------------------------
B:cl_bm char(7) *
cl_dw char(7) *
cl_kc dec(9,3)
---------------------------
C:wzbm char(7)*
wzmc varchar(30)
ggxh varchar(30)
jldw char(6)
---------------------------
SELECT C.WZBM AS WZBM,A.CL_DW AS DW_A,A.CL_KC AS KC_A,B.CL_DW AS DW_B,B.CL_KC AS KC_B
INTO #TMP_CL
FROM A RIGHT JOIN C ON A.CL_BM=C.WZBM
LEFT JOIN B ON B.CL_BM=C.WZBM
SELECT * FROM #TMP_CL
结果为:
WZBM DW_A KC_A DW_B KC_B
0001 SC 10 NULL NULL
0002 CQ 10 SC 10
0003 CQ 10 CQ 10
0004 NULL NULL SC 10
我需要的结果为:
WZBM DW KC
0001 SC 10
0002 CQ 10
0002 SC 10
0003 CQ 20
0004 SC 10
A:cl_bm char(7) *
cl_dw char(7) *
cl_kc dec(9,3)
---------------------------
B:cl_bm char(7) *
cl_dw char(7) *
cl_kc dec(9,3)
---------------------------
C:wzbm char(7)*
wzmc varchar(30)
ggxh varchar(30)
jldw char(6)
---------------------------
SELECT C.WZBM AS WZBM,A.CL_DW AS DW_A,A.CL_KC AS KC_A,B.CL_DW AS DW_B,B.CL_KC AS KC_B
INTO #TMP_CL
FROM A RIGHT JOIN C ON A.CL_BM=C.WZBM
LEFT JOIN B ON B.CL_BM=C.WZBM
SELECT * FROM #TMP_CL
结果为:
WZBM DW_A KC_A DW_B KC_B
0001 SC 10 NULL NULL
0002 CQ 10 SC 10
0003 CQ 10 CQ 10
0004 NULL NULL SC 10
我需要的结果为:
WZBM DW KC
0001 SC 10
0002 CQ 10
0002 SC 10
0003 CQ 20
0004 SC 10