发布网友 发布时间:2022-05-01 07:02
共2个回答
懂视网 时间:2022-05-01 11:24
SELECT [ ALL | DISTINCT | DISTINCT ON (distinct_expressions) ]
expressions
FROM tables
[WHERE conditions]
[GROUP BY expressions]
[HAVING condition]
[ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS FIRST | NULLS LAST ]]
[LIMIT [ number_rows | ALL]
[OFFSET offset_value [ ROW | ROWS ]]
[FETCH { FIRST | NEXT } [ fetch_rows ] { ROW | ROWS } ONLY]
[FOR { UPDATE | SHARE } OF table [ NOWAIT ]]; //这归纳了select几乎所有的用法,由于select用法极其复杂,下面只给出一些比较常见的用例。关于比较高级的用法我会在后续博客中进行详细分析。
select sno,sname,ssex,sdept from student where sage<20 or sdept=‘MA‘; //条件查询
select * from student where sage<20 union select * from student where sdept=‘MA‘; //集合查询
select sno,sname from student where sno in(select sno from student where sdept=‘MA‘); //嵌套查询
UPDATE table
SET column1 = expression1 | DEFAULT,
column2 = expression2 | DEFAULT,
...
[WHERE conditions]; //update用法很简单
update student set sname=‘李勇‘ where sno=‘01‘;
update student set sname=‘王芳‘ where sno=‘02‘;
update student set sname=‘张立‘ where sno=‘03‘;
update student set sname=‘王敏‘ where sno=‘04‘;
update student set sname=‘刘晨‘ where sno=‘05‘;
update student set sname=‘黎勇‘ where sno=‘06‘;
select * from student;
DELETE FROM table
[WHERE conditions]; //delete也很简单
delete from student where sno=‘06‘;
INSERT INTO table
(column1, column2, ... )
VALUES
(expression1 | DEFAULT, expression2 | DEFAULT, ... ),
(expression1 | DEFAULT, expression2 | DEFAULT, ... ),
...; //增删查改四种操作,只有select比较复杂,别的都很简单。
insert into student values(‘06‘,‘李伟‘,‘M‘,18,‘IS‘);
explain select sno,sname from student where sage<20 and sdept=‘MA‘;
postgreDB之学习笔记(一)
标签:
热心网友 时间:2022-05-01 08:32
处理办法如下: