oraclewith嵌套with_oracle with as 用法

With查询语句已with开头,相当于在查询之前先构建一个临时表,被指定的查询结果存与临时表中,之后便可多次使用它做进一步的分析和处理。

语法:with _tempTable as (select * from table )

select  * from _tempTable

例子:with _tempStudent as(

select * from t_student t where class = '初二3班'

)

select sex,count(1) nums from _tempStudent where sex = '男' and height > '170'

union all

select sex,count(1) nums from _tempStudent where sex = '女' and height > '160'

多个with as 用法 每个临时存量直接用 "," 隔开with t1 as (

select * from student where name in('张三','李四')

),t2 as (

select * from student where name in('王五')

)

select * from t1

union

select * from t2

如果with as 有嵌套的情况, 多个with as,后面的as内部可以直接调用先声明的临时对象with t1 as (

select * from student where name in('张三','李四')

),t2 as (

select * from t1 where name in('王五')

)

select * from t2

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值