pg学习_子查询
来源:互联网 发布:2017淘宝热卖产品 编辑:程序博客网 时间:2024/05/17 08:39
子查询子查询的语法SELECT select_list FROM tableWHERE expr operator(SELECT select_list FROM table);子查询规则 ()最好放在右边,提高查询的速度。子查询类型有两种:单行子查询多行子查询1、单行子查询1)单行子查询所用的操作符号 =>>=< <=<>简单的单行子查询highgo=# select * from testhighgo-# where no >(select no from test where name='adam');组函数的子查询highgo=# select * from testhighgo-# where no >(select max(no) from test where name='adam'); no | name ----+-------- 3 | eva 3 | lilith(2 rows)having 语句使用子查询highgo=# select no,count(*) from test group by nohighgo-# having no>(select min(no) from test where name='adam'); no | count ----+------- 3 | 2 2 | 2(2 rows)2、多行子查询多行子查询所用的操作符号 inany 大于> 大于最小小于< 小于最大等于= 相对于 in all 大于> 大于最大 小于< 小于最小highgo=# select * from testhighgo-# where no in (select no from test where name='adam'); no | name ----+-------- 1 | adam 2 | lilith 1 | lilith 1 | eva 2 | adam(5 rows)highgo=# select * from testhighgo-# where no > any (select no from test where name='adam'); no | name ----+-------- 2 | lilith 3 | eva 2 | adam 3 | lilith(4 rows)highgo=# select * from testhighgo-# where no > all (select no from test where name='adam'); no | name ----+-------- 3 | eva 3 | lilith(2 rows)3、子查询作from子句在进一步优化后的 HighGo DB 中,当子查询作为 from 的子句时允许不添加别名,这与 oracle 做到了充分的兼容。highgo=# select * fromhighgo-# (select * from test where name='adam')where no=1; no | name ----+------ 1 | adam(1 row)
0 0
- pg学习_子查询
- pg学习_数据查询
- pg学习_数据更新
- pg学习_集合操作
- pg学习_函数类型
- pg学习_运算符,表达式
- pg学习_多表连接
- 05-Oracle学习_子查询 和 连接查询
- 06-Oracle学习_练习-子查询 和 连接查询
- pg学习_基本表定义_创建表
- pg学习_基本表定义_数据类型
- pg学习_基本表定义_约束关系
- pg学习_基本表定义_修改表结构
- pg查询表所拥有的子表
- oracle学习笔记(6)_子查询
- pg学习_视图、序列、触发器、存储过程
- PostgreSQL查询优化的分享---PG优化器的框架和子查询
- pg 查询执行计划
- 素数筛法
- pg学习_数据查询
- How to use fasterxml Jackson JSON serialization in Spring 4
- 34. Search for a Range
- 失败成就伟大:谷歌的23个失败案例
- pg学习_子查询
- 两张图快速理解[区块链]
- 快排nth_element
- CCFCSP201412-2Z字形扫描
- pg学习_多表连接
- 统计概念总结
- 将一个网络分为两个子网 通过已知IP和子网掩码计算其同一网段的主机IP
- 工厂数据管理系统
- 多线程个人问题汇总