私は 3 つのテーブルを持っています。同じものを簡略化したバージョンを提示しています。
Customer_dim
[Cust_id] [Cust_Name]
Product_dim
[Prod_id] [Prod_Name]
Orders_fact
[ord_id] [Cust_id] [Prod_id]
すべての商品を購入してくださったすべてのお客様 (1 つも欠けていない) が欲しい
各顧客グループの数を顧客グループの合計数と単純に同等にするよりも、より洗練されたクエリが必要です。prod_dim
つまり、以下の種類のクエリは必要ありません (インタビューの質問であり、エレガンスにもポイントがあるため)
select cust_name
from customers c,
(select cust_id, count(prod_id) cnt
from order_fact
group by cust_id where cnt = (select count(prod_id) from prod_dim)) t1
where c.cust_id = t1.cust_id