SQL查詢初學者指南讀書筆記(二)建立SQL查詢,初學者指南sql
PARTII: SQL Basics
CHAPTER 4Creating a Simple Query
介紹一種如何建立SQL語句的技術--“Request/Translation/CleanUp/SQL”
The SELECT operationin SQL can be broken down into three smaller operations,
which we will referto as the SELECT statement,the SELECT expression,
and the SELECTquery.
一層包含一層,相互嵌套使用,可以構成非常複雜的SELECT.
SELECT Statement的其它關鍵詞都比較熟悉,這兒稍微解釋GROUP BY和HAVING
GROUP BY—When youuse aggregate functions in the SELECT clause
to produce summaryinformation, you use the GROUP BY clause to
divide theinformation into distinct groups.Your database system uses
any column or listof columns following the GROUP BY keywords as
grouping columns.The GROUP BY clause is optional, and we’ll examine
it further inChapter 13, Grouping Data.
HAVING—The HAVINGclause filters the result of aggregate functions
in groupedinformation. It is similar to the WHERE clause in that the
HAVING keyword isfollowed by an expression that evaluates to true,
false, orunknown.You can test the expression by using standard comparison
operators, Booleanoperators, or special operators. HAVING is
also an optionalclause, and we’ll take a closer look at it in Chapter 14,
Filtering GroupedData.