吴裕雄 python oracle子查询的用法(3)
import cx_Oracle
conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")
cursor = conn.cursor()
sql = "select * from emp where deptno=(select deptno from dept where dname='%s')" % ('RESEARCH')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp join dept on emp.deptno=dept.deptno where dept.dname='%s'" % ('RESEARCH')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal>(select min(sal) from emp) and sal<(select max(sal) from emp)"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where deptno in (select deptno from dept where dname<>'%s')" % ('SALES')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal>any(select sal from emp where deptno=10)and deptno<>10"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal>all(select sal from emp where deptno=30)"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp f where sal>(select avg(sal) from emp where job=f.job)"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

吴裕雄 python oracle子查询的用法(3)的更多相关文章
- 吴裕雄 python oracle检索数据(2)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 吴裕雄 python oracle操作数据库(4)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- 吴裕雄 python oracle检索数据(1)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/ORCL")cursor = conn. ...
- Oracle子查询相关内容(包含TOP-N查询和分页查询)
本节介绍Oracle子查询的相关内容: 实例用到的数据为oracle中scott用户下的emp员工表,dept部门表,数据如下: 一.子查询 1.概念:嵌入在一个查询中的另一个查询语句,也就是说一个查 ...
- oracle 子查询和组合函数
oracle 子查询和组合函数 --查询与"SCOTT"在同一个部门的员工 select empno,ename,deptno from emp where deptno in ( ...
- 一道Oracle子查询小练习
一道Oracle子查询小练习 昨天晚上躺在床上看Oracle(最近在学习这个),室友说出个题目让我试试.题目如下: 有如下表结构,请选择出成绩为前三名的人的信息(如果成绩相同,则算并列),表名为t ...
- Oracle子查询之高级子查询
Oracle 高级子查询 高级子查询相对于简单子查询来说,返回的数据行不再是一列,而是多列数据. 1,多列子查询 主查询与子查询返回的多个列进行比较 查询与141号或174号员工的manager_id ...
- Oracle 子查询
1.子查询在SELECT.UPDATE.DELETE语句内部可以出现SELECT语句.内部的SELECT语句结果可以作为外部语句中条件子句的一部分,也可以作为外部查询的临时表.子查询的类型有: ① 单 ...
- oracle 子查询因子化 浅谈(with的使用)
近来学习oracle,想要提高自己所写语句的效率和易读性,今天的笔记是关于子查询因子话这么一个东西 因子化的查询不一定可以提高效率,但是一定可以再提高程序的可读性方面成效显著 --with 语句 wi ...
随机推荐
- 「ZJOI2015」地震后的幻想乡
/* 难度最低的解法 钦定一个边集S作为前S小如果这个边集假如第|S|小这条边时加入时S恰好联通, 那么我们就能够算出他的贡献了 恰好联通 = 加了这条边之前不连通方案数 - 加了这条边之后不连通方案 ...
- log4js 2.X版本配置详解
const log4js = require('log4js'); log4js.configure({ appenders: { cheese: { type: 'file', filename: ...
- 了解Katalon的安装及基本使用(for mac)
一.整体了解: 2018 top 6的自动化测试工具(网上了解): 1. Selenium 2. Katalon Studio 3. UFT 4. Watir 5. IBM Rational Func ...
- jsfiddle修改个人头像
找了半天终于知道修改jsfiddle头像的方法了~ JsFiddle将Gravatar - 全球认可的头像用于个人资料图片.必须在这里改变你的头像,它也会在jsFiddle中自动更新. 注意,两者的注 ...
- 2014年第五届蓝桥杯JavaB组省赛试题解析
题目及解析如下: 题目大致介绍: 第一题到第三题以及第六题是结果填空,方法不限只要得到最后结果就行 第四题和第五题是代码填空题,主要考察算法基本功和编程基本功 第七题到第十题是编程题,要求编程解决问题 ...
- HDU1848 Fibonacci again and again 博弈 SG函数
题意:三堆石子,每次能拿走斐波那契数个石子,先取完石子胜,问先手胜还是后手胜 石子个数<=1000 多组数据 题目链接:http://acm.hdu.edu.cn/showproblem.ph ...
- spring boot 下载
- Maven上传jar包到私服
1.认证,在M2_HOME/conf/settings.xml配置用户名密码 <server> <id>releases</id> <username> ...
- mysql source 命令导入不了sql!
sql文件也是正常, 为什么就是导入不了呢?? 后面才发现,可能是编码被notepad++ 修改了—— 一看发现是UTF-8 无BOM,改回UTF-8格式编码 就正常了!! 虽然看到的都是正常汉字, ...
- Linux 硬链接、软链接
索引节点 inode(index node) 我们知道文件都有文件名与数据,这在 Linux 上被分成两个部分:用户数据 (user data) 与元数据 (metadata).用户数据,即文件数据块 ...