【发布时间】:2020-11-04 14:41:58
【问题描述】:
场景:有一个有四列的表。 District_Number、District_name、Data_Collection_Week、注册。每周我们都会获得数据,但有时我们不会。 任务:我的主管希望我生成一个查询,让我们知道哪些地区在给定的一周内没有提交。 我尝试过的如下,但是对于那些没有提交一周的人,我无法获得 NULL 值。
SELECT DISTINCT DistrictNumber, DistrictName, DataCollectionWeek
into #test4
FROM EDW_REQUESTS.INSTRUCTION_DELIVERY_ENROLLMENT_2021
order by DistrictNumber, DataCollectionWeek asc
select DISTINCT DataCollectionWeek
into #test5
from EDW_REQUESTS.INSTRUCTION_DELIVERY_ENROLLMENT_2021
order by DataCollectionWeek
select b.DistrictNumber, b.DistrictName, b.DataCollectionWeek
from #test5 a left outer join #test4 b on (a.DataCollectionWeek = b.DataCollectionWeek)
order by b.DistrictNumber, b.DataCollectionWeek asc
【问题讨论】:
标签: sql sql-server tsql subquery distinct