Leetcode HARD 2991 - Top Three Wineries MAX IFNULL CONCAT SQL - Explained by Everyday Data Science

Опубликовано: 23 Октябрь 2024
на канале: Everyday Data Science
270
12

Question: https://leetcode.com/problems/top-thr...

SQL Schema:
Create table if Not Exists Wineries ( id int, country varchar(60), points int, winery varchar(60))
Truncate table Wineries
insert into Wineries (id, country, points, winery) values ('103', 'Australia', '84', 'WhisperingPines')
insert into Wineries (id, country, points, winery) values ('737', 'Australia', '85', 'GrapesGalore')
insert into Wineries (id, country, points, winery) values ('848', 'Australia', '100', 'HarmonyHill')
insert into Wineries (id, country, points, winery) values ('222', 'Hungary', '60', 'MoonlitCellars')
insert into Wineries (id, country, points, winery) values ('116', 'USA', '47', 'RoyalVines')
insert into Wineries (id, country, points, winery) values ('124', 'USA', '45', 'Eagle'sNest')
insert into Wineries (id, country, points, winery) values ('648', 'India', '69', 'SunsetVines')
insert into Wineries (id, country, points, winery) values ('894', 'USA', '39', 'RoyalVines')
insert into Wineries (id, country, points, winery) values ('677', 'USA', '9', 'PacificCrest')

Pandas Schema:
data = [[103, 'Australia', 84, 'WhisperingPines'], [737, 'Australia', 85, 'GrapesGalore'], [848, 'Australia', 100, 'HarmonyHill'], [222, 'Hungary', 60, 'MoonlitCellars'], [116, 'USA', 47, 'RoyalVines'], [124, 'USA', 45, "Eagle'sNest"], [648, 'India', 69, 'SunsetVines'], [894, 'USA', 39, 'RoyalVines'], [677, 'USA', 9, 'PacificCrest']]
wineries = pd.DataFrame(data, columns=['id', 'country', 'points', 'winery']).astype({'id':'Int64', 'country':'object', 'points':'Int64', 'winery':'object'})

#leetcodesolutions #datascience #sql