1
は、私はまた、これらのテーブル参加のお客様とタグテーブル
Customers
CustomerNumber date
001 8/1/2017
002 8/2/2017
003 8/3/2017
Tags
Index Tag Description
1 NEW New customer
2 OTHER Some other tag
Customers_Tags
TagIndex CustomerNumber
1 001
1 002
2 002
2 003
どのように私は、単一のクエリでは、タグ1とすべての顧客を得ることができ、それらの顧客が持っている任意の他のタグを持っていますか?だから、タグ1のgetを探している場合:
customer tag date
001 1 8/1/2017
002 1 8/2/2017
002 2 8/2/2017
ありがとうございます、完璧な作品です。これに顧客のタグ数を追加する簡単な方法はありますか? –
@PatrickSchomburg 'select ...、CustomerTagCount = count(*)over(partition by ct.customernumber)'のようなウィンドウ関数として 'count()'を使うことができます。 – SqlZim
ありがとう、ありがとう。 –