标签:数据库 内容 最小 val init com 内连接 选择 value
非原创,转自Github:enochtangg/quick-SQL-cheatsheet
SQL 语句用法的速查表。
SELECT
* FROM
table_name;SELECT DISTINCT
column_name;SELECT
column1, column2 FROM
table_name WHERE
condition;SELECT
* FROM
table_name WHERE
condition1 AND
condition2;SELECT
* FROM
table_name WHERE
condition1 OR
condition2;SELECT
* FROM
table_name WHERE NOT
condition;SELECT
* FROM
table_name WHERE
condition1 AND
(condition2 OR
condition3);SELECT
* FROM
table_name WHERE EXISTS
(SELECT
column_name FROM
table_name WHERE
condition);SELECT
* FROM
table_name ORDER BY
column;SELECT
* FROM
table_name ORDER BY
column DESC
;SELECT
* FROM
table_name ORDER BY
column1 ASC
, column2 DESC
;SELECT TOP
number columns_names FROM
table_name WHERE
condition;SELECT TOP
percent columns_names FROM
table_name WHERE
condition;SELECT TOP
。 MySQL 中是LIMIT
子句SELECT
column_names FROM
table_name LIMIT
offset, count;SELECT
column_names FROM
table_name WHERE
column_name LIKE
pattern;LIKE
‘a%’ (查找任何以“a”开头的值)LIKE
‘%a’ (查找任何以“a”结尾的值)LIKE
‘%or%’ (查找任何包含“or”的值)LIKE
‘_r%’ (查找任何第二位是“r”的值)LIKE
‘a_%_%’ (查找任何以“a”开头且长度至少为3的值)LIKE
‘[a-c]%’(查找任何以“a”或“b”或“c”开头的值)SELECT
column_names FROM
table_name WHERE
column_name IN
(value1, value2, …);SELECT
column_names FROM
table_name WHERE
column_name IN
(SELECT STATEMENT
);SELECT
column_names FROM
table_name WHERE
column_name BETWEEN
value1 AND
value2;SELECT
* FROM
Products WHERE
(column_name BETWEEN
value1 AND
value2) AND NOT
column_name2 IN
(value3, value4);SELECT
* FROM
Products WHERE
column_name BETWEEN
#01/07/1999# AND #03/12/1999#;SELECT
* FROM
table_name WHERE
column_name IS NULL
;SELECT
* FROM
table_name WHERE
column_name IS NOT NULL
;SELECT
column_name AS
alias_name FROM
table_name;SELECT
column_name FROM
table_name AS
alias_name;SELECT
column_name AS
alias_name1, column_name2 AS
alias_name2;SELECT
column_name1, column_name2 + ‘, ‘ + column_name3 AS
alias_name;SELECT
columns_names FROM
table1 UNION SELECT
column_name FROM
table2;UNION
仅允许选择不同的值, UNION ALL
允许重复ANY
如果任何子查询值满足条件,则返回 true。ALL
如果任何子查询值满足条件,则返回 true。SELECT
columns_names FROM
table1 WHERE
column_name operator (ANY
|ALL
) (SELECT
column_name FROM
table_name WHERE
condition);SELECT
column_name1, COUNT(column_name2) FROM
table_name WHERE
condition GROUP BY
column_name1 ORDER BY
COUNT(column_name2) DESC;SELECT
COUNT
(column_name1), column_name2 FROM
table GROUP BY
column_name2 HAVING
COUNT(
column_name1)
> 5;INSERT INTO
table_name (column1, column2) VALUES
(value1, value2);INSERT INTO
table_name VALUES
(value1, value2 …);UPDATE
table_name SET
column1 = value1, column2 = value2 WHERE
condition;UPDATE
table_name SET
column_name = value;DELETE FROM
table_name WHERE
condition;DELETE
* FROM
table_name;SELECT COUNT (DISTINCT
column_name)
;SELECT MIN (
column_names) FROM
table_name WHERE
condition;SELECT MAX (
column_names) FROM
table_name WHERE
condition;SELECT AVG (
column_name) FROM
table_name WHERE
condition;SELECT SUM (
column_name) FROM
table_name WHERE
condition;SELECT
column_names FROM
table1 INNER JOIN
table2 ON
table1.column_name=table2.column_name;SELECT
table1.column_name1, table2.column_name2, table3.column_name3 FROM
((table1 INNER JOIN
table2 ON
relationship) INNER JOIN
table3 ON
relationship);SELECT
column_names FROM
table1 LEFT JOIN
table2 ON
table1.column_name=table2.column_name;SELECT
column_names FROM
table1 RIGHT JOIN
table2 ON
table1.column_name=table2.column_name;SELECT
column_names FROM
table1 FULL OUTER JOIN
table2 ON
table1.column_name=table2.column_name;SELECT
column_names FROM
table1 T1, table1 T2 WHERE
condition;CREATE VIEW
view_name AS SELECT
column1, column2 FROM
table_name WHERE
condition;SELECT
* FROM
view_name;DROP VIEW
view_name;ALTER TABLE
table_name ADD
column_name column_definition;ALTER TABLE
table_name MODIFY
column_name column_type;ALTER TABLE
table_name DROP COLUMN
column_name;标签:数据库 内容 最小 val init com 内连接 选择 value
原文地址:https://www.cnblogs.com/shanzhiming/p/10355743.html