1. 创建表(CREATE TABLE):
CREATE TABLE students (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
age INT,
grade VARCHAR(10)
);
2. 插入数据(INSERT INTO):
INSERT INTO students (name, age, grade) VALUES ('John Doe', 20, 'A');
3. 查询数据(SELECT):
SELECT * FROM students;
4. 更新数据(UPDATE):
UPDATE students SET age = 21 WHERE name = 'John Doe';
5. 删除数据(DELETE):
DELETE FROM students WHERE id = 1;
6. 条件查询(WHERE):
SELECT * FROM students WHERE age > 18;
7. 排序(ORDER BY):
SELECT * FROM students ORDER BY age DESC;
8. 聚合函数(SUM、AVG、COUNT):
SELECT AVG(age) FROM students;
这只是 SQL 的基础,PostgreSQL 还支持更复杂的查询、事务、视图、存储过程等高级功能。
转载请注明出处:http://www.zyzy.cn/article/detail/8098/PostgreSQL