简体   繁体   中英

Why am I getting an "Incorrect syntax near ')'" error for a CTE query?

I'm following Alex the Analyst's Portfolio Project for SQL Data Exploration (around the 59min mark) and I'm stuck on the "building a CTE" part:

WITH PopvsVac ( Continent, location, date, population, new_vaccinations, RollingPeopleVaccinated )
AS (
    SELECT
        dea.continent,
        dea.location,
        dea.date,
        dea.population,
        vac.new_vaccinations,
        SUM(CAST(vac.new_vaccinations AS bigint)) OVER (
            PARTITION BY dea.location
            ORDER BY dea.location, dea.date ROWS UNBOUNDED PRECEDING
        ) AS RollingPeopleVaccinated
    FROM
        PortfolioProject..CovidDeaths AS dea
        INNER JOIN PortfolioProject..CovidVaccinations AS vac ON 
            dea.location = vac.location
            AND
            dea.date = vac.date
    WHERE
        dea.continent IS NOT NULL
)

I understand that the original table has been updated since the video has been uploaded, which is why I've already made some adjustments to the query (bigint, ROWS UNBOUNDED PRECEDING), but I keep getting the

Msg 102, Level 15, State 1, Line 86
Incorrect syntax near ')'.

How can I fix it so I can get the desired CTE as a result of the query?

You need to use the CTE. For example...

-- Note, you do not need to repeat the column names.
with PopvsVac as (
  ...
)
select *
from PopvsVac;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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