Mysql语句整理大全
时间: 2023-07-25 12:23:52 浏览: 96
MySql语句大全
MySQL语句整理大全如下:
1. 创建数据库:
```
CREATE DATABASE database_name;
```
2. 删除数据库:
```
DROP DATABASE database_name;
```
3. 切换到指定数据库:
```
USE database_name;
```
4. 创建数据表:
```
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
.....
);
```
5. 删除数据表:
```
DROP TABLE table_name;
```
6. 插入数据:
```
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
```
7. 更新数据:
```
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
```
8. 删除数据:
```
DELETE FROM table_name WHERE condition;
```
9. 查询数据:
```
SELECT column1, column2, ... FROM table_name WHERE condition;
```
10. 查询数据并排序:
```
SELECT column1, column2, ... FROM table_name WHERE condition ORDER BY column1 ASC|DESC, column2 ASC|DESC, ...;
```
11. 查询数据并限制返回结果的数量:
```
SELECT column1, column2, ... FROM table_name WHERE condition LIMIT num;
```
12. 查询数据并分页:
```
SELECT column1, column2, ... FROM table_name WHERE condition LIMIT start, num;
```
13. 查询数据并计算统计值:
```
SELECT COUNT(column_name) FROM table_name WHERE condition;
```
14. 查询数据并计算平均值:
```
SELECT AVG(column_name) FROM table_name WHERE condition;
```
15. 查询数据并计算最大值:
```
SELECT MAX(column_name) FROM table_name WHERE condition;
```
16. 查询数据并计算最小值:
```
SELECT MIN(column_name) FROM table_name WHERE condition;
```
17. 查询数据并计算总和:
```
SELECT SUM(column_name) FROM table_name WHERE condition;
```
这些是MySQL语句的常见用法,希望对你有帮助。
阅读全文