这是我的数据库
我需要展示
1)订单中有1件以上的商品
2)每种产品的销售数量清单
ORDERS
Number_ord(PK) Buyer Delivery_address Date
1 Martin Chicago 2018-12-16
2 John Berlin 2018-12-17
3 Martin Chicago 2018-12-18
PRODUCTS
Number_prod Number_ord(FK) Qty
469841 1 15
469841 2 15
999999 2 6
558585 2 45
469841 3 15
844444 3 80
1)我写了类似的东西,但这是错误的
SELECT orders.Number_ord
FROM orders
join products USING(Number_ord)
GROUP BY COUNT(Number_prod)>1
2)这里,我也有问题
SELECT count(products.Number_prod),sum(products.Qty)
FROM orders
join products USING(Number_ord)
GROUP BY Number_prod
请帮助我
答案 0 :(得分:1)
您需要使用HAVING
来基于计数进行过滤。
SELECT orders.Number_ord, SUM(products.Qty)
FROM orders
JOIN products USING (Number_ord)
GROUP BY orders.Number_ord
HAVING COUNT(*) > 1