一、风哥PG-DBA培训05:PostgreSQL数据查询与SQL语句增删改
本课程由风哥发布的基于PostgreSQL数据库的系列课程,本课程属于PostgreSQL数据库SQL开发与应用实战阶段之PostgreSQL数据查询与SQL语句增删改,学完本课程可以掌握PostgreSQL SQL增删改, 插入数据(insert),修改数据(update),删除数据(delete),拷贝数据(copy),事务控制,PostgreSQL数据查询之SQL基本查询,SELECT功能与语法,from子句,表达式,WHERE子句,运算符,分组排序,HAVING子句,union与union all,WITH递归子句,PostgreSQL数据查询之SQL表联接,PostgreSQL数据查询之SQL子查询等技术内容,适合运维人员/数据库/开发人员,可以用于业务生产环境。风哥Oracle/MySQL/PG数据库学习专用QQ群:189070296、150201289
二、风哥PG-DBA培训05:PostgreSQL数据查询与SQL语句增删改
01.PostgreSQL SQL增删改
(*)插入数据(insert)
(*)修改数据(update)
(*)删除数据(delete)
(*)拷贝数据(copy)
(*)事务控制
02.PostgreSQL数据查询之SQL基本查询
(*)SELECT功能与语法
(*)from子句
(*)表达式
(*)WHERE子句
(*)运算符
(*)分组排序
(*)HAVING子句
(*)union与union all
(*)WITH递归子句
03.PostgreSQL数据查询之SQL表联接
(*)交叉连接
(*)条件连接-内连接
(*)条件连接-左外连接
(*)条件连接-右外连接
(*)条件连接-全外连接
04.PostgreSQL数据查询之SQL子查询
(*)简单的子查询
(*)写更复杂的子查询
(*)不同类型的子查询
--全表查询*
select * from itpux11;
select * from itpux11,itpux12; --笛卡尔
select * from itpux11 a1 where a1.name='itpux01';
select * from itpux11 a1,itpux12 a2
where
a1.name='itpux01';
select name from itpux12;
select * from itpux11;
select name,age from itpux12;
select name as 姓名,age as 年龄 from itpux12;
select * from itpux_yg limit 5;
select * from itpux_yg limit 5 offset 2;
select region from itpux_yg;
select distinct region from itpux_yg;
select * from itpux_yg where salary=10000;
select 10+20;
select 500*2345
select count(*) from itpux_yg;
select avg(salary) from itpux_yg;
select sum(salary) from itpux_yg;
select now();
select CURRENT_TIMESTAMP;
--where
select * from itpux11 a1 where a1.name='itpux01';
--and
select * from yg where manager_id=122 and salary>3000;
select * from itpux_yg where age>=35 and salary>=20000;
--or
select * from itpux_yg where age>=35 or salary>=20000;
--not null
select * from itpux12 where age is not null;
-- null
select * from itpux12 where age is null;
--like
select * from itpux_yg where name like 'itpux1000%';
select * from itpux_yg where name like 'itpux10%00';
select * from itpux_yg where name like '%0001';
--in
select * from itpux_yg where age in(35,36,37,38,39);
--exists
select * from itpux_yg where exists (select age from itpux_yg where salary > 20000);
运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。
PostgreSQL 运算符是一个保留关键字或字符,一般用在 WHERE 语句中,作为过滤条件。
常见的运算符有:
- 算术运算符
- 比较运算符
- 逻辑运算符
- 按位运算符
| 运算符 | 描述
| :----: | :------------
| + | 加
| - | 减
| * | 乘
| / | 除
| % | 模(取余)
| ^ | 指数
| |/ | 平方根
| ||/ | 立方根
select 5+3;
select 5-3;
select 5*3;
select 15/5;
select 15%4;
select 5^3;
select |/ 15.0;
select ||/ 18.0;
| 运算符 | 描述
| :----: | :------: |
| = | 等于 |
| != | 不等于
| <> | 不等于
| > | 大于 |
| < | 小于 |
| >= | 大于等于
| <= | 小于等于
select * from itpux12 where age=20;
select * from itpux12 where age!=20;
select * from itpux12 where age<>20;
select * from itpux12 where age>20;
select * from itpux12 where age>=20;
select * from itpux12 where age<20;
select * from itpux12 where age<=20;
PostgreSQL 逻辑运算符有以下几种:
AND逻辑与运算符
NOT逻辑非运算符
OR逻辑或运算符