我可以有一个示例“SELECT”查询,它包含所有where,orderby,having和groupby子句....
解释会有所帮助。
答案 0 :(得分:1)
今年客户为从最大到最小订购超过10,000美元的客户订单总结:
SELECT ClientName, SUM(OrderTotal) AS OrderTotal
FROM Orders
WHERE OrderDate >= '2012-01-01'
GROUP BY ClientName
HAVING SUM(OrderTotal) > 10000
ORDER BY SUM(OrderTotal) DESC
答案 1 :(得分:1)
SELECT Customer, SUM(OrderPrice) FROM Orders WHERE Customer='tehlulz' OR Customer='Vijay' GROUP BY Customer HAVING SUM(OrderPrice)>1500 ORDER BY Customer
稍微分解一下:
WHERE:用于定义条件。
HAVING:之所以使用是因为WHERE关键字不能与聚合函数一起使用。
GROUP BY:按特定字段对结果进行分组
ORDER BY:显示结果顺序(如价格从大到小)