【SQL Server】 两张相同字段的表拼接(Union)

SELECT date,name,code,times,times1 FROM ((
        SELECT
            t1.date,
            t1.NAME,
            t1.CODE,
            t1.times,
            t2.times1 
        FROM
            table1 t1
            LEFT JOIN table2 t2 ON t1.CODE = t2.CODE
UNION
        SELECT
            t2.date,
            t2.NAME,
            t2.CODE,
            t1.times,
            t2.times1 
        FROM
            table1 t1
            RIGHT JOIN table2 t2 ON t1.CODE = t2.CODE 
        WHERE
            t1.CODE IS NULL
)) AS temp ORDER BY date

 

posted @ 2022-09-22 19:25  陆陆无为而治者  阅读(620)  评论(0编辑  收藏  举报