mysql增删改查语句
时间: 2023-07-17 17:12:34 浏览: 85
MySql_增删改查语句
以下是MySQL中的常用增删改查语句示例:
1. 插入数据:
```
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...);
```
2. 更新数据:
```
UPDATE table_name
SET column1 = value1, column2 = value2,...
WHERE some_column = some_value;
```
3. 删除数据:
```
DELETE FROM table_name WHERE some_column = some_value;
```
4. 查询数据:
```
SELECT column1, column2, column3,... FROM table_name;
```
其中,SELECT语句还可以使用聚合函数,例如:
- COUNT:计算行数
```
SELECT COUNT(*) FROM table_name;
```
- AVG:计算平均值
```
SELECT AVG(column_name) FROM table_name;
```
- SUM:计算总和
```
SELECT SUM(column_name) FROM table_name;
```
- MAX:计算最大值
```
SELECT MAX(column_name) FROM table_name;
```
- MIN:计算最小值
```
SELECT MIN(column_name) FROM table_name;
```
另外,查询语句还可以使用WHERE子句进行条件筛选,例如:
```
SELECT column1, column2, column3,... FROM table_name WHERE column1 = 'value';
```
还可以使用ORDER BY子句进行排序,例如:
```
SELECT column1, column2, column3,... FROM table_name ORDER BY column1 ASC;
```
以上仅为MySQL中的部分常用语句示例,实际使用中需要根据具体情况进行调整。
阅读全文