sql 没有相交操作的查询

sql query with out intersect operation

查找大西洋地区所有购买过“TABLES”的客户以及购买的桌子数量(显示客户名称,no_of_tables 已购买)

我的 sql 不接受相交操作

select c.Customer_name,count(m.Prod_id) from cust_dimen c,market_fact m,prod_dimen p where m.Cust_id=c.Cust_id and p.Prod_id=m.Prod_id and Region='ATLANTIC' group by m.prod_id
intersect
select c.Customer_name,count(m.Prod_id) from  cust_dimen c,market_fact m,prod_dimen p where m.Cust_id=c.Cust_id and p.Prod_id=m.Prod_id and p.Product_Sub_Category='TABlES' group by m.Prod_id;

你能修改不相交吗

我看不出 intersect 对这个查询有什么帮助。我会采用 group by 的方法。条件只是过滤条件:

select c.Customer_name, count(m.Prod_id)
from cust_dimen c join
     market_fact m
     on m.Cust_id = c.Cust_id join
     prod_dimen p 
     on p.Prod_id = m.Prod_id 
where c.Region = 'ATLANTIC' and p.Product_Sub_Category = 'TABlES'
group by c.Customer_name;

忠告:永远不要FROM子句中使用逗号。 始终使用正确、明确、标准的JOIN语法。