希望此解决方案可以为您提供帮助(我使用的是SQL_Server语法)
SELECT isnull(date1,date2) as Date3, ISNULL(RM, 0 ),ISNULL(KM, 0 )
FROM table1
FULL JOIN table2
ON table1.Date1 = table2.Date2
order by Date3;
[结果]:
[编辑]:现场演示
create table Table1 (DATE1 date, RM int); INSERT INTO Table1 VALUES ('1/4/2020' , 1); INSERT INTO Table1 VALUES ('2/1/2020' , 4); INSERT INTO Table1 VALUES ('2/10/2020' , 4);
GO
3行受影响
create table Table2 (DATE2 date, KM int); INSERT INTO Table2 VALUES ('2/2/2020' , 1); INSERT INTO Table2 VALUES ('2/10/2020' , 3); INSERT INTO Table2 VALUES ('3/5/2020' , 2); GO
3行受影响
select * from Table1; GO
DATE1 | RM :--------- | -: 2020-01-04 | 1 2020-02-01 | 4 2020-02-10 | 4
select * from Table2; GO
DATE2 | KM :--------- | -: 2020-02-02 | 1 2020-02-10 | 3 2020-03-05 | 2
SELECT isnull(date1,date2) as Date3, ISNULL(RM, 0 ),ISNULL(KM, 0 ) FROM table1 FULL JOIN table2 ON table1.Date1 = table2.Date2 order by Date3; GO
日期3 | (无列名)| (无列名) :--------- | ---------------:| ---------------: 2020-01-04 | 1 | 0 2020-02-01 | 4 | 0 2020-02-02 | 0 | 1 2020-02-10 | 4 | 3 2020-03-05 | 0 | 2
db <>在这里拨弄
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句