COUNT Function
COUNT(*), COUNT(1), COUNT(column_name)
COUNT(*): 统计所有行,不管是否为NULLCOUNT(1): 统计所有代码行,不管是否为NULLCOUNT(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

Reference
- 本文链接:https://io.helltractor.top/posts/database/sql-tutorial-and-tricks
- 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 许可协议。