创建分组
SELECT vend_id, COUNT(*) AS num_prods FROM Profucts GROUP BY vend_id;
GROUP BY 子句必须出现在WHERE子句之后,OEDER BY子句之前。
过滤分组
SELECT cust_id, COUNT(*) AS orders FROM Orders GROUP BY cust_id HAVING COUNT(*) >= 2;
select子句顺序
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
子查询
SELECT cust_id FROM Orders WHERE order_num IN (SELECT order_num FROM OrderItems WHERE prod_id ='RGAN01');