一意ではない列を共有する2つのテーブルがあります。テーブルAにテーブルBよりも多くの共有列の値があるすべてのレコードが必要です。
TABLE A:
Shared_Column|User_ID|Department
123 | joe| sales
123 | joe| sales
123 | joe| sales
124 | sam| ops
124 | sam| ops
TABLE B
Shared_Column|Other_Column
123 | 1
123 | 1
124 | 4
124 | 4
このデータから、私は欲しいのですが、そうでjoe|sales
はありませんsam|ops
。これを出力として使用することもできます。
USER|TABLE_A_COUNT|TABLE_B_COUNT
joe| 3| 2
sam| 2| 2
編集:私はこのような参加をしようとしました:
select a.user_ID, count(a.shared_column) as 'TABLE_A_COUNT', count(b.shared_column) as 'TABLE_B_COUNT'
from a inner join b on a.shared_column = b.shared_column
group by a.user_ID
しかし、それはクロスジョインを生成するようjoe|6|6
で、3と2の代わりに取得します
ありがとう!