加入两个表以获得特定格式的第三列

时间:2016-11-24 01:26:36

标签: sql-server

嗨我在sqlserver中有Table1和Table2。我希望得到如表3中的结果,如下图所示。

enter image description here

3 个答案:

答案 0 :(得分:2)

这个查询终于给了我答案:

SELECT COALESECE(t1.Label, t2.label) AS label,
       t1.Value AS Table1_Value,
       t2.Value AS Table2_Value
FROM Table_1 t1
FULL OUTER JOIN Table_2 t2
    ON t1.Label = t2.Label

答案 1 :(得分:1)

尝试以下查询

 SELECT COALESCE(T1.LABEL,T2.LABEL) AS LABEL,T1.VALUE,T2.VALUE
 FROM TAB1 T1 FULL OUTER JOIN TAB2 T2
 ON T1.LABEL=T2.LABEL

答案 2 :(得分:0)

使用此查询:

SELECT t1.Label,
       t1.Value AS Table1_Value,
       t2.Value AS Table2_Value
FROM Table1 t1
FULL OUTER JOIN Table2 t2
    ON t1.Label = t2.Label

enter image description here