sql SQL基础知识。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SQL基础知识。相关的知识,希望对你有一定的参考价值。

UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
SELECT column1, column2, ...
FROM table1, table2
WHERE condition1, condition2, ...

SELECT table1.column1, table1.column2, table2.column1, ...
FROM table1
JOIN table2
ON table1.t1_id = table2.t1_id
WHERE contidion1, condition2, ...

SELECT table1.column1, table1.column2, table2.column1, table3.column2
FROM table1
JOIN table2
ON table1.t1_id = table2.t1_id
JOIN table3
ON table2.t2_id = table3.t2_id
WHERE contidion1, condition2, ...
SELECT * 
FROM table1

SELECT column1, column2, ...
FROM table1

SELECT column1, column2, ...
FROM table1
WHERE condition(s)

SELECT DISTINCT column1, column2, ...
FROM table1

SELECT column1, column2, ...
FROM table1
ORDER BY column1, column2, ... DESC

SELECT column1 AS alias1, column2 AS alias2, ...
FROM table1

SELECT column1, column2, COUNT(*)
FROM table1
GROUP BY column1, column2

SELECT column1, SUM(column2)
FROM table1
GROUP BY column1

SELECT column1, column2, AVG(column3)
FROM table1
GROUP BY column1, column2                   # Equivalent (and less error-prone): GROUP BY 1, 2

SELECT column1, column2, ...
FROM table1
GROUP BY 1, 2, ...                          # We need to group by each column we select and don't aggregate
HAVING condition1, condition2, ...          # We can't call WHERE in aggregate functions (to test the result of aggregation)
INSERT INTO table
(column1, column2, ... )
VALUES
(expression1, expression2, ... );

INSERT INTO table
(column1, column2, ... )
SELECT expression1, expression2, ...
FROM source_tables
WHERE conditions;
DELETE FROM table_name
WHERE some_column=some_value;

以上是关于sql SQL基础知识。的主要内容,如果未能解决你的问题,请参考以下文章

MySQL SQL的基础应用

SQL基础教程的内容简介

sql SQL基础知识。

sql SQL基础知识。

sql SQL基础知识。

T-SQL进阶02.理解SQL查询的底层原理