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. 网页的缓存Cache与控制

    什么是缓存 Cache? 缓存位于客户端与服务器之间, 或者服务器与服务器之间.它决定是否保存所获资源的副本,以及如何使用副本,何时更新副本,这里所说的资源包括页面的HTML, 图片,文件等等. 使用 ...

  2. tkinter简单使用

    第一个运行程序 # -*- coding: utf-8 -*- import tkinter as tk //引入 root = tk.Tk() // 实例化root T大写k小写 root.titl ...

  3. virsh详解

    来个表情包表达我此时的心情 man virsh virsh [options]... [<command_string>] virsh [options]... <command&g ...

  4. redis的哨兵集群,redis-cluster

    #主从同步redis主从优先1.保证数据安全,主从机器两份数据一主多从2.读写分离,缓解主库压力主redis,可读可写slave身份,只读   缺点1.手动主从切换假如主库挂了,得手动切换master ...

  5. android 开发 写一个RecyclerView布局的聊天室,并且添加RecyclerView的点击事件

    实现思维顺序: 1.首先我们需要准备2张.9的png图片(一张图片为左边聊天泡泡,一个图片为右边的聊天泡泡),可以使用draw9patch.bat工具制作,任何图片导入到drawable中. 2.需要 ...

  6. [Unity工具]CSV工具类

    参考链接: https://www.cnblogs.com/lulianqi/p/6385503.html http://blog.csdn.net/paul342/article/details/2 ...

  7. getdate — 取得日期/时间信息-----参数是一个 integer 的 Unix 时间戳

      <?php$today = getdate();print_r($today);?> Array ( [seconds] => 40 [minutes] => 58 [ho ...

  8. GitHub使用指南之快速入门

    出自http://blog.csdn.net/column/details/13170.html 1.Git安装 Git是一个版本控制系统,使用之前必须先下载安装,下面提供各平台的安装方式. Mac: ...

  9. workerman-todpole 执行流程(2)

    上一篇文章 workerman-todpole 执行流程(1),我们已经分析完了主进程的执行流程,这篇文章主要分析一下子进程的 run() 流程. 有必要提一下,在 run() 开始之前,其实针对角色 ...

  10. django之block extend标签

    class ExtendsNode(Node): must_be_first = True context_key = 'extends_context' def __init__(self, nod ...