赞
踩
以下是一些常用的MySQL查询语句示例:
1. 查询所有数据:
SELECT * FROM table_name;
2. 查询特定列数据:
SELECT column1, column2 FROM table_name;
3. 带条件查询:
SELECT * FROM table_name WHERE condition;
4. 模糊查询:
SELECT * FROM table_name WHERE column_name LIKE 'keyword%';
5. 排序查询:
SELECT * FROM table_name ORDER BY column_name ASC/DESC;
6. 限制结果数量:
SELECT * FROM table_name LIMIT 10;
7. 分页查询:
SELECT * FROM table_name LIMIT 20 OFFSET 40;
8. 聚合函数查询:
SELECT COUNT(*), AVG(column_name), SUM(column_name) FROM table_name;
9. 多表连接查询:
SELECT t1.column1, t2.column2 FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.id;
10. 条件分组统计:
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
11. 子查询:
SELECT column1 FROM table_name WHERE column2 IN (SELECT column2 FROM another_table);
12. 更新数据:
UPDATE table_name SET column_name = new_value WHERE condition;
13. 插入数据:
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
14. 删除数据:
DELETE FROM table_name WHERE condition;
15. 修改表结构:
ALTER TABLE table_name ADD column_name datatype;
以上是一些常用的MySQL查询语句示例,希望对你有帮助!如有需要,请根据具体情况进行调整和扩展。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。