创建临时 table 并插入子查询时在 "INSERT" 处或附近出现语法错误--PostgreSQL 错误
syntax error at or near "INSERT" when creating a temp table and insert into a subquery--PostgreSQL Error
我创建了一个临时 table 和 insert into
一个子查询,但我收到一条错误消息 'syntax error at or near "INSERT"'。任何人都可以有想法吗?谢谢!
CREATE TABLE population_vaccinated2
(
continent VARCHAR(200),
location VARCHAR(200),
date DATE,
population INT,
new_vaccinations NUMERIC,
aggre_vaccinations NUMERIC
)
INSERT INTO population_vaccinated2
SELECT
dea.continent, dea.location, dea.date, dea.population,
vac.new_vaccinations,
SUM(vac.new_vaccinations) OVER (PARTITION BY dea.location ORDER BY dea.location, dea.date) AS aggre_vaccinations
FROM
covid_deaths AS dea
JOIN
covid_vaccinations AS vac ON dea.location = vac.location
AND dea.date = vac.date
请注意,CREATE TABLE
和 INSERT INTO
是 两个不同的陈述。你需要在它们之间插入一个;
:
...
)
;
INSERT INTO ...
I created a temp table
请注意,这不是临时 table,因为您缺少 TEMPORARY
关键字。
我创建了一个临时 table 和 insert into
一个子查询,但我收到一条错误消息 'syntax error at or near "INSERT"'。任何人都可以有想法吗?谢谢!
CREATE TABLE population_vaccinated2
(
continent VARCHAR(200),
location VARCHAR(200),
date DATE,
population INT,
new_vaccinations NUMERIC,
aggre_vaccinations NUMERIC
)
INSERT INTO population_vaccinated2
SELECT
dea.continent, dea.location, dea.date, dea.population,
vac.new_vaccinations,
SUM(vac.new_vaccinations) OVER (PARTITION BY dea.location ORDER BY dea.location, dea.date) AS aggre_vaccinations
FROM
covid_deaths AS dea
JOIN
covid_vaccinations AS vac ON dea.location = vac.location
AND dea.date = vac.date
请注意,CREATE TABLE
和 INSERT INTO
是 两个不同的陈述。你需要在它们之间插入一个;
:
...
)
;
INSERT INTO ...
I created a temp table
请注意,这不是临时 table,因为您缺少 TEMPORARY
关键字。