Home >php教程 >php手册 >SQL中HAVING从句的用法

SQL中HAVING从句的用法

WBOY
WBOYOriginal
2016-06-13 10:06:011037browse

HAVING
用户在使用SQL语言的过程中可能希望解决的一个问题就是对由sum或其它集合函数运算结果的输出进行限制。例如,我们可能只希望看到Store_Information数据表中销售总额超过1500美圆的商店的信息,这时我们就需要使用HAVING从句。语法格式为:
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)
(GROUP BY从句可选)
由此,我们可以使用如下命令实现上述查询目的:
SELECT store_name, SUM(sales)
FROM Store_Information
GROUP BY store_name
HAVING SUM(sales) > 1500
查询结果显示为:
store_name SUM(Sales)
Los Angeles $1800
小注:
SQL语言中设定集合函数的查询条件时使用HAVING从句而不是WHERE从句。通常情况下,HAVING从句被放置在SQL命令的结尾处


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn