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. 03 Linux的目录结构与常见文件管理

    Linux目录结构 根文件系统rootfs用来实现整个文件的管理: 而Linux下的所有文件都需要通过根文件系统才能访问: FHS:Filesystem Hierarchy Standard文件层次化 ...

  2. CS229 6.2 Neurons Networks Backpropagation Algorithm

    今天得主题是BP算法.大规模的神经网络可以使用batch gradient descent算法求解,也可以使用 stochastic gradient descent 算法,求解的关键问题在于求得每层 ...

  3. h5登录页面

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  4. hive使用map字段

    create table role_bigtable(table_name string, record_date string, server_id string, map_col map<s ...

  5. appium java 在android7.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式

    1.找到appium的安装目录下的adb.js文件,目录为:Appium\node_modules\appium\node_modules\appium-adb\lib 2.打开adb.js,找到如下 ...

  6. mac上使用jmeter录制web项目和手机app

    前言: 最近熟悉jmeter进行带宽测试和并发测试,发现网上大多都是windows版本,自己用的mac,实验后发现大同小异 1.下载,我使用的jmeter3.2的版本,可以在网上下载,不区分mac版和 ...

  7. 使用tpcc-mysql进行性能测试

    tpcc-mysql的github地址:https://github.com/Percona-Lab/tpcc-mysql tpcc-mysql源代码进行编译,服务器上需要安装有mysql git c ...

  8. Geany 编辑器打开 高亮所选单词 功能

    Geany 编辑器打开 高亮所选单词 功能 在Ubuntu 系统的Software Center 工具中,搜索到geany, 下方有个 Miscellanous Plugins for Geany, ...

  9. python中的center

    center(self,width,fillchar=None)让字符串居中显示,width定义字长度,fillchar定义空白处填充,不填写默认为空白 举个列子: 1 a = "hello ...

  10. linux write/wall 1

    linux:/opt/software/lktest/c # wallhellllllllllllllllllllooooooooooooooooo^[[AasZZZZZZ^Clinux:/opt/s ...