DB2 中的查询计数

raj*_*aji 1 sql db2 count

在大型机 DB2 中,我有两个表 TAB 1 和 TAB 2。这些表中的记录如下:

选项卡 1:

AP_NBR  LOC_NBR
1000    1
1000    2
1000    3
Run Code Online (Sandbox Code Playgroud)

选项卡 2:

LOC_NBR ITM_ID
1   500
1   600
2   450
2   750
Run Code Online (Sandbox Code Playgroud)

她我需要如下输出:

AP_NBR  COUNT(LOC_NBR)  COUNT(ITM_ID)
1000    3                     4
Run Code Online (Sandbox Code Playgroud)

如何为此编写 COUNT 查询?有人可以帮我解决这个问题吗?

Gri*_*aub 5

select t1.AP_NBR, count(distinct t1.LOC_NBR), count(distinct t2.ITM_ID)
from TAB1 t1 join TAB2 t2 on t1.LOC_NBR = t2.LOC_NBR
group by t1.AP_NBR
Run Code Online (Sandbox Code Playgroud)