GROUP BY 函数和HAVING()函数.

Group By函数用于分组,以某一列名来进行分组,将相同项合并

HAVING 子句

在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与合计函数一起使用。

SQL HAVING 语法

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

例如:
SELECT Customer,SUM(OrderPrice) FROM Orders
WHERE Customer='Bush' OR Customer='Adams'
GROUP BY Customer
HAVING SUM(OrderPrice)>1500

posted @ 2014-12-29 15:49  静以养身 俭以养德  阅读(139)  评论(0编辑  收藏  举报