最近學到的,使用with來簡化query,用起來想先create一些臨時的table,這樣可以避免寫嵌套的subqueries。效果應該是一樣的
例子如下:
with temp1 as (
select a, b from table1
),
temp2 as (
select c, d from table2
)
select
temp1.a,
temp2.c
from
temp1
join
temp2
on
temp1.b = temp2.d
程序|生活|學到就是賺到
最近學到的,使用with來簡化query,用起來想先create一些臨時的table,這樣可以避免寫嵌套的subqueries。效果應該是一樣的
例子如下:
with temp1 as (
select a, b from table1
),
temp2 as (
select c, d from table2
)
select
temp1.a,
temp2.c
from
temp1
join
temp2
on
temp1.b = temp2.d