SQL语句中常用的函数及表之间的关联

常用函数

AVG() - 返回平均值(SELECT AVG(column_name) FROM table_name WHERE condition;
COUNT() - 返回行数(SELECT COUNT(1) FROM table_name WHERE condition;
MAX() - 返回最大值(SELECT MAX(column_name) FROM table_name WHERE condition;
MIN() - 返回最小值(SELECT MIN(column_name) FROM table_name WHERE condition;
SUM() - 返回总和(SELECT SUM(column_name) FROM table_name WHERE condition;

数据表之间的关联

INNER JOIN:如果表中有至少一个匹配,则返回行(取两个表的交集SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
LEFT JOIN:即使右表中没有匹配,也从左表返回所有的行(取左表的全集SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name;
RIGHT JOIN:即使左表中没有匹配,也从右表返回所有的行(取右表的全集SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
FULL JOIN:只要其中一个表中存在匹配,则返回行(取两个表的并集SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;

SQL语句中常用的函数及表之间的关联

上一篇:nginx: [emerg] bind() to 0.0.0.0:9001 failed (10013: An attempt was made to access a socket in a way)


下一篇:MySql