执行 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
select
clause outside of aggregate functions must appear ingroup by
list
- Note: Attributes in
- 通过
having
来 filter result- Note: Before SQL-93, attributes in
having
conditions must NOT appear ingroup by
list
- Note: Before SQL-93, attributes in
NULL Value
算数
在算数中,NULL 进行任何运算,还是 NULL。如 5 * (7 + NULL) = NULL。
逻辑
在逻辑中,NULL 进行任何逻辑判断,都是 Unknown。
- 除了
is NULL
和is not NULL
而 Unknown 和其它的逻辑进行判断,就是以下四个:
聚合
除了 COUNT(*)
以外,其它的聚合函数直接会忽略 NULL。