with

博客展示了SQL中WITH子句的多种使用方式,包括基本查询、链式CTE、联合查询、插入操作、创建表、创建视图等示例,通过不同代码片段呈现了WITH子句在不同场景下的应用,有助于理解其在SQL查询中的灵活运用。

with q1 as ( select key from src where key = ‘5’)

select *

from q1;

– from style

with q1 as (select * from src where key= ‘5’)

from q1

select *;

– chaining CTEs

with q1 as ( select key from q2 where key = ‘5’),

q2 as ( select key from src where key = ‘5’)

select * from (select key from q1) a;

– union example

with q1 as (select * from src where key= ‘5’),

q2 as (select * from src s2 where key = ‘4’)

select * from q1 union all select * from q2;

– insert example

create table s1 like src;

with q1 as ( select key, value from src where key = ‘5’)

from q1

insert overwrite table s1

select *;

– ctas example

create table s2 as

with q1 as ( select key from src where key = ‘4’)

select * from q1;

– view example

create view v1 as

with q1 as ( select key from src where key = ‘5’)

select * from q1;

select * from v1;

– view example, name collision

create view v1 as

with q1 as ( select key from src where key = ‘5’)

select * from q1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值