0
  1. < with tbl as > 是否比 < create table tbl as >快得多?
   with tbl as 
   (
    select 
      id,name 
    from 
      a
   )
   select id from tbl;

   create table tbl 
   as 
   select 
      id,name 
   from 
      a;

   select id from tbl;
  1. 如果我想在许多查询中使用 tbl,如何使用 <和 tbl as >?
    with tbl as 
   (
    select 
      id,name 
    from 
      a
   )
   select id from tbl;

   select name from tbl;

4

1 回答 1

0
  1. 没有明显的性能差距。

  2. with tbl as是一个公用表表达式,又名 CTE,只能在单个查询中访问。所以我们不能跨多个 SQL 查询使用 CTE,以;.

  3. 人情create temporary table表结束create table。前者在单个会话中可见,并且会在会话结束时消失。

于 2020-01-18T03:14:01.773 回答