在mySQL上写一个查询,查询每个销售人员对每种产品的销售总额,其中每个销售人员在MySQL上销售一种以上产品
表为:
product(Product_id,Product_name,price),
推销员(Salesman_id,Salesman_name),
销售(Sales_id,Salesman_id,Product_id,数量)
到目前为止,我已经尝试过该查询:
collection/resource
我找不到错误“ sales.count不存在”的错误代码:1630
答案 0 :(得分:2)
请勿在{{1}}和HAVING
之间的COUNT
子句中放置空格
尝试一下:
(
答案 1 :(得分:0)
我认为该查询更适合您的要求:
select s.Salesman_id,sm.Salesman_name,sum(Quantity) as TotalSales
from sales s
join product p
on s.Product_id=p.Product_id
join salesman sm
on sm.Salesman_id=s.Salesman_id
group by s.Salesman_id, sm.Salesman_name
having count(p.Product_id)>1