3. SQL Syntax
执行 pipeline¶
SELECT column1, aggregate_function(column2) AS aggr
FROM table_name
WHERE condition
GROUP BY column1
HAVING condition;
执行的 pipeline 就是:
- 通过
where来 filter table - 通过
group by和 aggregation function 来分组+聚合- Note: Attributes in
selectclause outside of aggregate functions must appear ingroup bylist
- Note: Attributes in
- 通过
having来 filter result- Note: Before SQL-93, attributes in
havingconditions must NOT appear ingroup bylist
- Note: Before SQL-93, attributes in
NULL Value¶
算数¶
在算数中,NULL 进行任何运算,还是 NULL。如 5 * (7 + NULL) = NULL。
逻辑¶
在逻辑中,NULL 进行任何逻辑判断,都是 Unknown。
- 除了
is NULL和is not NULL
而 Unknown 和其它的逻辑进行判断,就是以下四个:

聚合¶
除了 COUNT(*) 以外,其它的聚合函数直接会忽略 NULL。