数据查询:
1. SELECT语句:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
2. DISTINCT关键字:
SELECT DISTINCT column1, column2, ...
FROM table_name;
3. ORDER BY子句:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1 ASC, column2 DESC;
4. LIMIT和OFFSET(或FETCH):
SELECT column1, column2, ...
FROM table_name
LIMIT 10 OFFSET 20;
5. WHERE子句的逻辑运算符:
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 OR condition3;
数据过滤:
1. LIKE运算符:
SELECT column1, column2, ...
FROM table_name
WHERE column_name LIKE 'pattern';
2. IN运算符:
SELECT column1, column2, ...
FROM table_name
WHERE column_name IN (value1, value2, ...);
3. BETWEEN运算符:
SELECT column1, column2, ...
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
聚合和分组:
1. GROUP BY子句:
SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1;
2. HAVING子句:
SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1
HAVING COUNT(*) > 1;
3. 聚合函数(SUM、AVG、MAX、MIN):
SELECT AVG(column1), MAX(column2)
FROM table_name
WHERE condition;
修改数据:
1. INSERT INTO语句:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
2. UPDATE语句:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
3. DELETE FROM语句:
DELETE FROM table_name
WHERE condition;
这只是 SQL 语句的一小部分,涵盖了一些常见的用法。具体的语法和功能可能因使用的数据库管理系统而有所不同。在使用时,请查阅相应数据库的文档以获取更详细和准确的信息。
转载请注明出处:http://www.zyzy.cn/article/detail/3322/SQL