我有地区和月份:
80 | San Diego | 1
80 | San Diego | 2
80 | San Diego | 3
80 | San Diego | 4
80 | San Diego | 5
80 | San Diego | 6
80 | San Diego | 7
80 | San Diego | 8
80 | San Diego | 9
80 | San Diego | 10
80 | San Diego | 11
80 | San Diego | 12
74 | Tampa | 1
74 | Tampa | 2
74 | Tampa | 3
74 | Tampa | 4
74 | Tampa | 5
74 | Tampa | 6
74 | Tampa | 7
74 | Tampa | 8
74 | Tampa | 9
74 | Tampa | 10
74 | Tampa | 11
74 | Tampa | 12
64 | Denver | 1
64 | Denver | 2
64 | Denver | 3
64 | Denver | 4
64 | Denver | 5
64 | Denver | 6
64 | Denver | 7
64 | Denver | 8
64 | Denver | 9
64 | Denver | 10
64 | Denver | 11
64 | Denver | 12
我也计算了一下:
74 | Tampa | 12 | 100
74 | Tampa | 6 | 80
80 | San Diego | 7 | 50
如何连接这些表以获得:
80 | San Diego | 1 |
80 | San Diego | 2 |
80 | San Diego | 3 |
80 | San Diego | 4 |
80 | San Diego | 5 | 50
80 | San Diego | 6 |
80 | San Diego | 7 |
80 | San Diego | 8 |
80 | San Diego | 9 |
80 | San Diego | 10 |
80 | San Diego | 11 |
80 | San Diego | 12 |
74 | Tampa | 1 |
74 | Tampa | 2 |
74 | Tampa | 3 |
74 | Tampa | 4 |
74 | Tampa | 5 |
74 | Tampa | 6 | 80
74 | Tampa | 7 |
74 | Tampa | 8 |
74 | Tampa | 9 |
74 | Tampa | 10 |
74 | Tampa | 11 |
74 | Tampa | 12 | 100
正如你所看到的,Denver
应该从第一个结果集中过滤出来。
1条答案
按热度按时间sqougxex1#
使用窗口函数计算每个区域的计算总和(
c
CTE)以及总和为0的过滤器区域。这是丹佛的下降。我假设第一个表名为t
,第二个表名为-s
。参见DB Fiddle demo
这里使用
group by
。DB Fiddle demo