SELECT location, MAX(cast(total_deaths as int)) as HighestDeathCount
FROM portfolio_1.CovidDeaths
Where continent is not null
Group by location
order by HighestDeathCount DESC
limit 1000
SELECT continent, Max(cast(Total_deaths as int)) as TotalDeathCount
FROM portfolio_1.CovidDeaths
Where continent is null and location not like '%income%'
Group by continent
order by TotalDeathCount DESC
limit 1000
SELECT date, SUM(new_cases) , Sum(new_deaths), SUM(new_cases)/ Sum(new_deaths) *100 as DeathPercentage
-- total_deaths, (total_deaths/total_cases)*100 as DeathPercentage
FROM portfolio_1.CovidDeaths
Where continent is null and location not like '%income%'
Group by date
limit 100
Expected keyword AS but got "(" at [1:15]
With PopvsVac as
(
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
From onyx-smoke-380601.portfolio_1.CovidDeaths dea
Join onyx-smoke-380601.portfolio_1.CovidVaccinations vac
On dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
)
Select *, (RollingPeopleVaccinated/Population)*100
From PopvsVac
Create or Replace Table portfolio_1.PercentPopulationVaccinated
(
Continent STRING,
Location STRING,
Date datetime,
Population numeric,
New_vaccinations numeric,
RollingPeopleVaccinated numeric
);
Insert into portfolio_1.PercentPopulationVaccinated
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
From onyx-smoke-380601.portfolio_1.CovidDeaths dea
Join onyx-smoke-380601.portfolio_1.CovidVaccinations vac
On dea.location = vac.location
and dea.date = vac.date
;
Select *, (RollingPeopleVaccinated/Population)*100
From portfolio_1.PercentPopulationVaccinated
Create View portfolio_1.PercentPopulationVaccinated as
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
From onyx-smoke-380601.portfolio_1.CovidDeaths dea
Join onyx-smoke-380601.portfolio_1.CovidVaccinations vac
On dea.location = vac.location
and dea.date = vac.date
where dea.continent is not null
Select *
From portfolio_1.PercentPopulationVaccinated
'Programming > Google Data Analytics Certificate' 카테고리의 다른 글
SQL Practice (0) | 2023.04.06 |
---|---|
R (0) | 2023.04.05 |
[GA] 구글 애널리틱스 프로그램 - R 기초 (0) | 2023.04.04 |
[GA] 구글 애널리틱스 프로그램 - R 기초 (0) | 2023.04.04 |
[GA] 구글 애널리틱스 프로그램 - R 기초 (0) | 2023.04.03 |