总结一下最常用的30条sql查询语句

  1. 查询所有表:
SELECT * FROM information_schema.tables;
  1. 查询表中的所有数据:
SELECT * FROM table_name;
  1. 查询表中特定的列:
SELECT column_name FROM table_name;
  1. 按条件查询数据:
SELECT * FROM table_name WHERE condition;
  1. 按条件查询唯一的一行数据:
SELECT * FROM table_name WHERE condition LIMIT 1;
  1. 按条件查询多个列:
SELECT column1, column2 FROM table_name WHERE condition;
  1. 查询并排序结果:
SELECT column1, column2 FROM table_name ORDER BY column1 ASC;
  1. 查询结果去重:
SELECT DISTINCT column1 FROM table_name;
  1. 查询结果分页:
SELECT * FROM table_name LIMIT offset, count;
  1. 统计行数:
SELECT COUNT(*) FROM table_name;
  1. 求和:
SELECT SUM(column) FROM table_name;
  1. 求平均值:
SELECT AVG(column) FROM table_name;
  1. 求最大值:
SELECT MAX(column) FROM table_name;
  1. 求最小值:
SELECT MIN(column) FROM table_name;
  1. 查询满足多个条件的数据:
SELECT * FROM table_name WHERE condition1 AND condition2;
  1. 查询满足任一条件的数据:
SELECT * FROM table_name WHERE condition1 OR condition2;
  1. 使用通配符查询:
SELECT * FROM table_name WHERE column LIKE 'value%';
  1. 多表查询:
SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;
  1. 子查询:
SELECT column1 FROM table1 WHERE column2 IN (SELECT column3 FROM table2);
  1. 使用聚合函数查询:
SELECT COUNT(column) FROM table_name GROUP BY column;
  1. 分组查询:
SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;
  1. 更新数据:
UPDATE table_name SET column1 = 'new_value' WHERE condition;
  1. 插入数据:
INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2');
  1. 删除数据:
DELETE FROM table_name WHERE condition;
  1. 创建表:
CREATE TABLE table_name (column1 data_type, column2 data_type);
  1. 修改表结构:
ALTER TABLE table_name ADD column data_type;
  1. 删除表:
DROP TABLE table_name;
  1. 创建索引:
CREATE INDEX index_name ON table_name (column);
  1. 删除索引:
DROP INDEX index_name;
  1. 查询表结构:
DESCRIBE table_name;

已发布

分类

标签:

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注