如何将(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
我需要将结果放入新表中。
答案 0 :(得分: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语句的源:
insert into foo (col1, col2)
with a as (
...
), b as (
...
)
select ambtemp,dt
from B
where (max_temp - min_temp) <= 0.2