-1

我需要一点帮助...

我有两个数据表:

已编程线路表(理论行程) 在此处输入图像描述 卖家覆盖线路表(实际行程) 在此处输入图像描述 要达到的结果:

在此处输入图像描述 谢谢...

4

2 回答 2

0
select isnull(a.date, b.date), isnull(a.seller, b.seller), a.[theoretical itinerary], b.[real itinerary] 
from table1 a full join table2 b 
on a.date=b.date and a.seller=b.seller
于 2018-04-17T15:27:30.320 回答
0

我想你想要full join

select coalesce(t.date, r.date) as date, coalesce(t.seller, r.seller) as seller,
       t.itinerary as theoretical_itinerary,
       r.itinerary as real_itinerary
from theoretical t full join
     real r
     on t.date = r.date and t.seller = r.seller;

coalesce()使用full join. 如果不包括它,那么您将看到NULL匹配列的值。(如果只支持 SQL Server using,那么会有一个简单的替代方案。)

于 2018-04-17T15:27:41.140 回答