创建数据库:
CREATE DATABASE database_name;
删除数据库:
DROP DATABASE database_name;
选择数据库:
USE database_name;
创建表:
CREATE TABLE table_name ( column1 datatype [condition], column2 datatype [condition], ...);
删除表:
DROP TABLE table_name;
插入数据:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
更新数据:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
删除数据:
DELETE FROM table_name WHERE condition;
查询数据:
SELECT column1, column2, ... FROM table_name WHERE condition;
查询数据(无条件):
SELECT * FROM table_name;
查询排序:
SELECT * FROM table_name ORDER BY column1 ASC|DESC;
查询去重:
SELECT DISTINCT column1 FROM table_name;
查询计数:
SELECT COUNT(*) FROM table_name;
查询条件:
SELECT * FROM table_name WHERE column1 = value1 AND column2 < value2;
模糊查询(通配符 %):
SELECT * FROM table_name WHERE column1 LIKE 'value%';
聚合函数(求和、平均值、最大值、最小值):
SELECT SUM(column1), AVG(column2), MAX(column3), MIN(column4) FROM table_name;
分组查询:
SELECT column1, COUNT(*) FROM table_name GROUP BY column1;
连接表查询(内连接、左连接、右连接、全连接):
SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;
创建索引:
CREATE INDEX index_name ON table_name (column1, column2, ...);
删除索引:
DROP INDEX index_name ON table_name;
来源地址:https://blog.csdn.net/weixin_53902288/article/details/132707253