[英]SQL: is it possible to combine an INSERT and SELECT statement into one
[英]how to combine a WITH statement and an INSERT INTO in SQL
我有一個帶有 with 子句的 sql 語句,我想將結果寫入帶有插入的表中。 我嘗試過的 with 和 insert into 的任何組合都會給我一條錯誤消息。 我想做的最小例子:
create table temp as (quarter decimal(5));
insert into temp (
with bla as (select 2021 as year from dummy)
select 10*year + 1 as quarter from bla
)
將 with 語句放在 insert into 之外也不起作用。
對於 Oracle,您需要以下語法:
insert into temp (quarter)
with bla (year) as (
select 2021 as year from dual
)
select 10*year + 1 as quarter from bla;
你的CREATE TABLE
語句應該是:
create table temp (quarter decimal(5));
db<> 在這里擺弄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.