選択クエリで結合しようとしている 2 つのテーブルがあります。
表 1: ストア、primary_key(id,store_num)
store_id store_num due_date manager_id
1 100 06-30-2024 user1
2 108 06-30-2018 user2
3 109 13-31-2014 user3
表 2: 部門、ステータス (A-適用済み、p-保留中)
store_id store_num dept_num status
1 100 201 A
1 100 202 A
1 100 203 P
1 100 204 A
1 100 205 P
1 100 206 A
store_id、store_num、due_date、manager_id、Applied count、pending count を選択する予定です。結果はこんな感じです。
store_id store_num due_date manager_id applied_count pending_count
1 100 06-30-2024 user1 4 2
私はそれを試してみましたが、参加して複数の行で取得できる場所に到達しましたが、うまくいきません。カウントを取得する方法を教えてください
select
store.store_id,
store.store_num,
store.due_date,
store.manager_id,
dept.status
from store as store
inner join department as dept on store.store_id = dept.store_id
and store.store_num = dept.store_num