我正在尝试获取客户列表,然后按客户分组销售,下面的代码可行,但不是我想要的。
我真的跟每个客户一起展示了每个客户的所有销售额。
SELECT i.item, i.Qty, c.NAME, c.address, s.OrderNo, s.OrderDate
FROM CUSTOMERS c
LEFT JOIN Sales s
ON c.name = s.cust
LEFT JOIN Items i
on i.OrderNo = s.OrderNo
WHERE s.Cust IS not NULL
答案 0 :(得分:0)
- 从销售表中按客户SubQuery总计值,然后加入到该表中。 SELECT i.item,i.Qty,c.NAME,c.address,s.OrderNo,s.OrderDate,s.SUM_CUSTOMER_SALES_VALUE 来自客户c LEFT JOIN(SELECT Cust,SUM(CUSTOMER_SALES_VALUE)AS SUM_CUSTOMER_SALES_VALUE来自Sales GROUP BY Cust)s ON c.name = s.cust LEFT JOIN项目i 在i.OrderNo = s.OrderNo WHERE s.Cust IS not NULL