sql-server - 无法在 SQL 中创建视图
问题描述
Create view PercentPopulationVaccinated as
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
,sum(convert(int,vac.new_vaccinations)) OVER (Partition by dea.location order by dea.location,
dea.date) as rolling_people_vaccinated
from PortfolioProject..['Covid vaccinations$'] vac
Join PortfolioProject..['Covid deaths$'] dea
On dea.location=vac.location
and dea.date=vac.date
where dea.continent is not null
--order by 2,3
Select *
from PercentPopulationVaccinated
我想创建一个视图,但我不断收到此错误
消息 156,级别 15,状态 1,过程 PercentPopulationVaccinated,第 12 行 [批处理开始行 127]
关键字“选择”附近的语法不正确。
解决方案
这批中有 2 条语句。CREATE VIEW 必须是批处理中的唯一语句。从批处理中删除第二个 SELECT 语句。如果您在 SSMS 中执行此操作,您还可以在 CREATE VIEW 语句和最后一个 SELECT 之间添加 GO。
Create view PercentPopulationVaccinated as
Select dea.continent, dea.location, dea.date, dea.population, vac.new_vaccinations
,sum(convert(int,vac.new_vaccinations)) OVER (Partition by dea.location order by dea.location,
dea.date) as rolling_people_vaccinated
from PortfolioProject..['Covid vaccinations$'] vac
Join PortfolioProject..['Covid deaths$'] dea
On dea.location=vac.location
and dea.date=vac.date
where dea.continent is not null
--order by 2,3
GO
Select *
from PercentPopulationVaccinated
推荐阅读
- optimization - 有没有办法将 teradata show stats 值的结果加载到表中?
- tensorflow - 是否可以使用深度学习库(Tensorflow、PyTorch、MXNet)来训练 Botframework 模型?
- node.js - Dialogflow:检查用户是否连续发送 X 条消息
- python - 如何在python中删除或清除打印的文本
- javascript - 如何使用带有 CSS-in-JS 的 React 重写此按钮及其悬停效果
- ios - 使用“弹出式”VC 时,背景模糊效果无明显原因
- php - 在没有数据库的情况下保存和编辑文本数据的最佳方法
- python - 我如何为字符串的最终出现制作正则表达式
- java - 如何在循环中使最接近的数字为零
- c# - 如何在 c# 中将图像保存为具有透明度的 gif?