使用mysql创建临时表时出现语法错误1064

3yhwsihp  于 2022-11-21  发布在  Mysql
关注(0)|答案(2)|浏览(331)

我一直在第2行的创建表附近得到语法错误。请我能做些什么。我已经尝试和搜索到我所知道的一切。

CREATE TEMPORARY TABLE #percentpopulationvaccinated
(
continent VARCHAR(200),
location VARCHAR(200),
date DATE,
population INT,
new_vaccinations NUMERIC,
currentPeopleVaccinated NUMERIC
)
INSERT INTO #percentpopulationvaccinated
SELECT dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations, SUM(CAST(vac.new_vaccinations as unsigned)) OVER (Partition By dea.location ORDER BY dea.location, dea.date) AS currentPeopleVaccinated
FROM portfolioproject.coviddeaths dea
INNER JOIN portfolioproject.covidvaccinations vac
    ON dea.location = vac.location
    AND dea.date = vac.date
WHERE dea.continent is not null
SELECT*, (currentPeopleVaccinated/population)*100
FROM #percentpopulationvaccinated
k3bvogb1

k3bvogb11#

MySQL客户端将#及其后面的文本视为注解,这意味着就MySQL所知,您已经编写了以下查询:

CREATE TEMPORARY TABLE 
(
...

临时表没有名称,难怪会出现语法错误!
有关MySQL注解语法的信息,请参见https://dev.mysql.com/doc/refman/8.0/en/comments.html

50pmv0ei

50pmv0ei2#

对于临时表,请尝试使用以下命令:

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 
RollingPeopleVaccinated
INTO TEMPORARY TABLE percentpopulationvaccinated
FROM "CovidDeaths" as dea
JOIN "CovidVaccinations" as vac
ON dea."date" = vac."date" AND dea."location" = vac."location"
WHERE dea.continent IS NOT NULL AND dea.continent !=''

SELECT *,(RollingPeopleVaccinated/population)*100 as rol_per_pop FROM 
percentpopulationvaccinated

相关问题