covid_10012023_covid-reports/src/data/enums/CustomPreparedStatementsRea...

78 lines
2.9 KiB
Java

package data.enums;
/**
* Holds prepared data for Read-based SQL queries.
*/
public enum CustomPreparedStatementsRead {
DailyInfectionsAndDeathAggregate("""
WITH matched_countries AS (
SELECT c.name, c.code
FROM countries c
WHERE c.name LIKE CONCAT('%',?, '%')
)
SELECT recorded_date, infections, deaths
FROM cases
WHERE iso_country IN (SELECT code FROM matched_countries) AND recorded_date <= ?
ORDER BY recorded_date
""",
"Daily infections and deaths up until, inside a range (incl. fuzzy search)"
),
HighestAndLowest10Vaccination("""
WITH vacc_count_per_country AS (
SELECT iso_country, SUM(daily_vaccinations) as total_vaccinations
FROM vaccinations
GROUP BY iso_country
)
SELECT name, total_vaccinations
FROM countries JOIN vacc_count_per_country
ON countries.code = vacc_count_per_country.iso_country
ORDER BY total_vaccinations DESC
LIMIT 10
;
WITH vacc_count_per_country AS (
SELECT iso_country, SUM(daily_vaccinations) as total_vaccinations
FROM vaccinations
GROUP BY iso_country
)
SELECT name, total_vaccinations
FROM countries JOIN vacc_count_per_country
ON countries.code = vacc_count_per_country.iso_country
ORDER BY total_vaccinations ASC
LIMIT 10
""",
"10 countries with the highest vaccinations (with count), and countries with lowest number of vaccinations."
),
HighestInfectionsPer100K("""
SELECT c.name, ((SUM(cases.infections) * 100000) / c.population) as infections_per_100k, c.population, SUM(cases.infections) as total_infections
FROM cases INNER JOIN countries c ON cases.iso_country = c.code
GROUP BY c.name, c.population
ORDER BY infections_per_100k DESC
LIMIT 10
""",
"10 countries with the highest infections per 100k inhabitants (with count)"
),
CountriesLaggingBehind("""
SELECT c.name
FROM countries c INNER JOIN (
SELECT iso_country, SUM(daily_vaccinations) as total_vaccinations
FROM vaccinations
GROUP BY iso_country
) v ON c.code = v.iso_country
WHERE v.total_vaccinations < c.population
""",
"Countries that haven't vaccinated their whole population with at least one shot or jab."
);
public final String statementTemplate;
public final String description;
CustomPreparedStatementsRead(String statementTemplate, String description) {
this.statementTemplate = statementTemplate;
this.description = description;
}
}