本文最后更新于 1 分钟前,文中所描述的信息可能已发生改变。
COUNT Function
COUNT(*)
, COUNT(1)
, COUNT(column_name)
COUNT(*)
: 统计所有行,不管是否为NULL
COUNT(1)
: 统计所有代码行,不管是否为NULL
COUNT(column_name)
: 统计指定列的行数,判断是否为NULL
Speed
COUNT(*)
和COUNT(1)
的速度是一样的,因为COUNT(*)
会统计所有列,而COUNT(1)
会统计所有代码行COUNT(*)
是SQL92定义的标准统计数的语法,所以速度会快一些COUNT(column_name)
会判断是否为NULL
,所以速度会慢一些
USING Function
The USING
clause is used to specify some condition to join tables.
sql
SELECT * FROM table1 JOIN table2 USING (column_name);
-- equal to
SELECT * FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
ORDER BY Clause
ORDER BY 1
order by the first column in the select list.
sql
SELECT * FROM table_name ORDER BY 1;
SELECT first_column, second_column FROM table_name ORDER BY 1;
JOIN Clause
JOIN Cheat Sheet
