使用MySQL创建临时表时获得语法ERORR 1064

发布于 2025-01-27 19:19:37 字数 796 浏览 3 评论 0原文

我一直在第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

i keep getting syntax error near create table in line 2. Please what can i do about it. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅 2025-02-03 19:19:37

MySQL客户端对待和与评论相同的行上的文本。据MySQL所知,您已经编写了此查询:

CREATE TEMPORARY TABLE 
(
...

临时表没有名称。难怪您有语法错误!

参见 https://dev.mysql.com/doc/doc/refman/8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0. /en/comments.html 有关MySQL评论语法的信息。

The MySQL client treats # and the text that follows it on the same line as a comment. This means as far as MySQL knows, you have written this query:

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.

萌酱 2025-02-03 19:19:37

尝试此命令以获取临时表:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文