Uodated queries

This commit is contained in:
Denis Donici 2025-03-13 21:56:07 +02:00
parent ad3c09fda0
commit 45744ea973
2 changed files with 39 additions and 0 deletions

Binary file not shown.

View File

@ -86,3 +86,42 @@ export const getHottestAndColdestCityInWorld = db.query(`
WHERE hottest_rank = 1 OR coldest_rank = 1 WHERE hottest_rank = 1 OR coldest_rank = 1
LIMIT 2 LIMIT 2
`); `);
export const getWorldTemperatureStats = db.query(`
WITH city_temps AS (
SELECT
c.id as city_id,
c.name as city_name,
c.country_id,
co.name as country_name,
md.max as max_temp,
md.min as min_temp,
md.date,
ROW_NUMBER() OVER (ORDER BY md.max DESC) as hottest_rank,
ROW_NUMBER() OVER (ORDER BY md.max ASC) as coldest_rank
FROM cities c
JOIN meteo_data md ON c.id = md.city_id
JOIN countries co ON c.country_id = co.id
WHERE md.date = $date
),
world_stats AS (
SELECT
ct1.city_id,
ct1.city_name,
ct1.country_id,
ct1.country_name,
ct1.max_temp,
ct1.date,
ct1.hottest_rank,
ct1.coldest_rank
FROM city_temps ct1
WHERE ct1.hottest_rank = 1 OR ct1.coldest_rank = 1
)
SELECT * FROM world_stats
ORDER BY max_temp DESC
LIMIT 2
`);