简体   繁体   English

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

[英]Getting syntax erorr 1064 when creating a temporary table using mysql

i keep getting syntax error near create table in line 2. Please what can i do about it.我在第 2 行的创建表附近不断收到语法错误。请问我该怎么办。 I have tried and search everywhere to my knowledge.据我所知,我已经尝试并到处搜索。

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

The MySQL client treats # and the text that follows it on the same line as a comment. MySQL 客户端将#及其后面的文本视为注释。 This means as far as MySQL knows, you have written this query:这意味着据 MySQL 所知,您已经编写了以下查询:

CREATE TEMPORARY TABLE 
(
...

There is no name for the temporary table.临时表没有名称。 No wonder you got a syntax error!难怪你会遇到语法错误!

See https://dev.mysql.com/doc/refman/8.0/en/comments.html for information on MySQL's comment syntax.有关 MySQL 注释语法的信息,请参阅https://dev.mysql.com/doc/refman/8.0/en/comments.html

Try this command for temporary tables:为临时表尝试此命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM