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)的更多相关文章

  1. 吴裕雄 python oracle检索数据(2)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...

  2. 吴裕雄 python oracle操作数据库(4)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...

  3. 吴裕雄 python oracle检索数据(1)

    import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/ORCL")cursor = conn. ...

  4. Oracle子查询相关内容(包含TOP-N查询和分页查询)

    本节介绍Oracle子查询的相关内容: 实例用到的数据为oracle中scott用户下的emp员工表,dept部门表,数据如下: 一.子查询 1.概念:嵌入在一个查询中的另一个查询语句,也就是说一个查 ...

  5. oracle 子查询和组合函数

    oracle 子查询和组合函数 --查询与"SCOTT"在同一个部门的员工 select empno,ename,deptno from emp where deptno in ( ...

  6. 一道Oracle子查询小练习

    一道Oracle子查询小练习   昨天晚上躺在床上看Oracle(最近在学习这个),室友说出个题目让我试试.题目如下: 有如下表结构,请选择出成绩为前三名的人的信息(如果成绩相同,则算并列),表名为t ...

  7. Oracle子查询之高级子查询

    Oracle 高级子查询 高级子查询相对于简单子查询来说,返回的数据行不再是一列,而是多列数据. 1,多列子查询 主查询与子查询返回的多个列进行比较 查询与141号或174号员工的manager_id ...

  8. Oracle 子查询

    1.子查询在SELECT.UPDATE.DELETE语句内部可以出现SELECT语句.内部的SELECT语句结果可以作为外部语句中条件子句的一部分,也可以作为外部查询的临时表.子查询的类型有: ① 单 ...

  9. oracle 子查询因子化 浅谈(with的使用)

    近来学习oracle,想要提高自己所写语句的效率和易读性,今天的笔记是关于子查询因子话这么一个东西 因子化的查询不一定可以提高效率,但是一定可以再提高程序的可读性方面成效显著 --with 语句 wi ...

随机推荐

  1. KVM CPU线程等学习记录

    绝大多数操作系统调度单位是线程.线程是调度和分配的基本单位,进程是资源拥有的基本单位.linux下fork的叫进程pthread叫线程创建进程比线程性能要差好多5-100倍,因进程不同而异.进程之间共 ...

  2. lunix 项目部署 *****

    linux基本管理命令 服务器上安装服务,python3.6(宿主机上的物理解释器)1.虚拟解释器virtualenv虚拟出多个干净.隔离的python解释器环境问题:管理上较为麻烦,需要找到venv ...

  3. python-运算符重载

    1. __item__ class X: def __init__(self, data=None): self.data = data or [] # 同样可用于 dict def __setite ...

  4. springBoot_freemark配置

    Spring Boot –test 1.添加依赖 <!-- 引入 spring-boot-starter-test 集成单元测试--> <dependency> <gro ...

  5. JAVA给图片添加水印

    package com.test; import org.junit.Test; import javax.imageio.ImageIO; import java.awt.*; import jav ...

  6. 57.1拓展之纯 CSS 创作黑暗中的眼睛和嘴巴

    效果地址:https://scrimba.com/c/cJ8NPpU2 HTML code: <div class="eyes"> <span class=&qu ...

  7. 《算法》第五章部分程序 part 3

    ▶ 书中第五章部分程序,包括在加上自己补充的代码,字符串高位优先排序(美国国旗排序) ● 美国国旗排序 package package01; import edu.princeton.cs.algs4 ...

  8. 《算法》第四章部分程序 part 8

    ▶ 书中第四章部分程序,包括在加上自己补充的代码,图中找欧拉路径 ● 无向图中寻找欧拉路径,只注释了与欧拉环不同的地方 package package01; import edu.princeton. ...

  9. linux系统安全更新

    um --security upgrade 一.参考文档:  https://blog.csdn.net/ubuntu64fan/article/details/80927212 二.Linux主机定 ...

  10. 转载:“error LNK1169: 找到一个或多个多重定义的符号”的解决方法

    转载来自:http://www.cnblogs.com/A-Song/archive/2012/03/23/2413782.html 问题描述如下: 有 三个源文件,A.h.B.cpp.C.cpp. ...