3

如何将(WITH Queries)的结果放入新表中。

相关代码为:

WITH A as (
SELECT ambtemp,dt,
       date_trunc('hour', dt)+
       CASE WHEN date_part('minute', dt) >= 30
            THEN interval '30 minutes'
            ELSE interval '0 minutes'
       END as t
FROM temm),


B as(
SELECT ambtemp,dt,

       max(ambtemp::float(23)) OVER (PARTITION BY t) as max_temp,
       min(ambtemp::float(23)) OVER (PARTITION BY t) as min_temp
FROM A)



SELECT ambtemp,dt     
FROM B
WHERE (max_temp - min_temp) <= 0.2

我需要将结果放入一个新表中。

4

1 回答 1

3

只需在 create table 语句中像任何其他选择一样使用它:

create table foo 
as
with a as (
  ...
), b as ( 
  ...
)
select ambtemp,dt     
from B
where (max_temp - min_temp) <= 0.2

或者,如果您已经拥有该表,请将其用作插入语句的源:

insert into foo (col1, col2)
with a as (
  ...
), b as ( 
  ...
)
select ambtemp,dt     
from B
where (max_temp - min_temp) <= 0.2
于 2012-12-03T11:16:13.860 回答