Мне было интересно, может ли кто-нибудь из вас помочь мне улучшить этот запрос
SELECT IF(cases.country_region LIKE '%Korea%', 'South Korea', IF(upper(cases.country_region) = 'IRAN (ISLAMIC REPUBLIC OF)', 'Iran',
IF(upper(cases.country_region) = 'REPUBLIC OF IRELAND', 'IRELAND',
IF(cases.country_region = 'United Kingdom', 'UK', IF(upper(cases.country_region) = 'REPUBLIC OF MOLDOVA', 'MOLDOVA', cases.country_region))))) as country, (SUM(cases.latitude)/COUNT(cases.latitude)) as latitude,
(SUM(cases.longitude)/COUNT(cases.longitude)) as longitude, SUM(case when cases.confirmed is null then 0 else cases.confirmed end) as total_confirmed,
SUM(case when cases.deaths is null then 0 else cases.deaths end) as total_deaths, SUM(case when cases.recovered is null then 0 else cases.recovered end) as total_recovered,
SUM(case when cases.active is null then 0 else cases.active end) as total_active_cases, MAX(cases.date) as last_update
FROM
`bigquery-public-data.covid19_jhu_csse.summary` cases
INNER JOIN (
SELECT c.country_region, MAX(c.date) as maxdate
FROM `bigquery-public-data.covid19_jhu_csse.summary` c
WHERE c.date <= '2020-05-07'
GROUP BY c.country_region
) lcases ON cases.country_region = lcases.country_region AND cases.date = lcases.maxdate
GROUP BY country
HAVING total_confirmed > 0
ORDER BY total_confirmed desc;
Я действительно не знаю, есть ли способ упростить первую часть IF (case).
Если у кого-то есть идеи, прокомментируйте ниже! Спасибо большое!