使用完整的联接并在单元格中具有无效值时,如何删除重复项



这是我的基本表:

编号| site_wt | site_wt_data | site_nwt | site_nwt_data a
| 1 | null | 1 | null

这是我的选择和完整连接:

 SELECT      Number,T1.site ,T2.site,T3.site ,T4.site   
     FROM [A] AS T1
     FULL JOIN [B] AS T2
        ON T1.number=T2.number  
     FULL JOIN [C] AS T3
        ON  T2.number = T3.number  
     FULL JOIN [D] AS T4
        ON T3.number=T4.number 

这是结果:

编号| site_wt | site_wt_data | site_nwt | site_nwt_data a | 1234
| null | null | null a | null | null | 1234
| null

我有 null 的问题,它打破了我的 join ,并且我有重复的问题,因为正确的结果必须是,每个不同的数字只有一行,任何建议,如何做

正确的结果:

编号| site_wt | site_wt_data | site_nwt | site_nwt_data a | 1234
| null | 1234 | null

使用max()

 SELECT      Number,MAX(T1.site) SITE_WT,MAX(T2.site)SITE_WT_DATA,MAX(T3.site)SITE_NWT ,MAX(T4.site) SITE_NWT_DATA  
         FROM [A] AS T1
         FULL JOIN [B] AS T2
            ON T1.number=T2.number  
         FULL JOIN [C] AS T3
            ON  T2.number = T3.number  
         FULL JOIN [D] AS T4
            ON T3.number=T4.number 
            GROUP BY Number

相关内容

  • 没有找到相关文章

最新更新