查询数据
选择数据
SELECT column1, column2 FROM table_name;
条件选择
SELECT * FROM table_name WHERE condition;
过滤和排序
排序
SELECT column1, column2 FROM table_name ORDER BY column1 ASC|DESC;
过滤重复行
SELECT DISTINCT column1, column2 FROM table_name;
过滤和聚合
聚合函数
SELECT COUNT(column1), AVG(column2), SUM(column3) FROM table_name WHERE condition;
分组和聚合
SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;
修改数据
插入数据
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
更新数据
UPDATE table_name SET column1 = value1 WHERE condition;
删除数据
DELETE FROM table_name WHERE condition;
连接表
内连接
SELECT column1, column2 FROM table1 INNER JOIN table2 ON table1.column = table2.column;
左连接
SELECT column1, column2 FROM table1 LEFT JOIN table2 ON table1.column = table2.column;
高级查询
子查询
SELECT column1 FROM table1 WHERE column2 IN (SELECT column2 FROM table2 WHERE condition);
联合查询
SELECT column1 FROM table1 UNION SELECT column1 FROM table2;
这只是一个简单的 SQL 快速参考,实际中可能会有更复杂的查询和操作。确保在实际使用时参考相应数据库系统的文档,因为 SQL 语法可能在不同的数据库系统中有些许差异。
转载请注明出处:http://www.zyzy.cn/article/detail/14074/SQL