用with子句的好处:
使用 WITH 子句, 可以避免在SELECT 语句中重复书写相同的语句块
WITH 子句将该子句中的语句块执行一次并存储到用户的临时表空间中
使用 WITH 子句可以提高查询效率
例子:
with
temp_from as (select * from test1),
temp_where as (select testid from test2)
select * from temp_from
where exists (select testid from temp_where where temp_from.testid = temp_where.testid)