mysql的sql语句
时间: 2023-11-12 12:58:26 浏览: 94
Mysql SQL语句
MySQL是一种关系型数据库管理系统,支持使用SQL语言进行数据的增删改查操作。以下是一些常用的SQL语句:
1. 创建数据库:
CREATE DATABASE database_name;
2. 删除数据库:
DROP DATABASE database_name;
3. 创建表:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
.....
);
4. 删除表:
DROP TABLE table_name;
5. 插入数据:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
6. 更新数据:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
7. 删除数据:
DELETE FROM table_name WHERE condition;
8. 查询数据:
SELECT column1, column2, ... FROM table_name WHERE condition;
9. 查询数据并排序:
SELECT column1, column2, ... FROM table_name WHERE condition ORDER BY column_name ASC|DESC;
10. 查询数据并分组:
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
11. 查询数据并计算平均值、最大值、最小值等:
SELECT AVG(column_name), MAX(column_name), MIN(column_name) FROM table_name WHERE condition;
12. 连接多个表查询数据:
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
13. 查询数据并使用LIKE进行模糊匹配:
SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
14. 查询数据并使用IN进行多条件匹配:
SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);
15. 查询数据并使用BETWEEN进行范围匹配:
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
16. 查询数据并使用LIMIT进行分页:
SELECT column_name(s) FROM table_name LIMIT offset, count;
阅读全文