LeetCode SQL Medium

Watch and track your favorite playlist.

Curated by: Everyday Data Science (140 videos)


Currently Playing: Leetcode MEDIUM 2986 - Find Third Transaction RANK() WINDOW - Explained by Everyday Data Science

Question: https://leetcode.com/problems/find-third-transaction/description/ SQL Schema: Create Table if Not Exists Transactions (user_id int, spend decimal(5,2), transaction_date datetime) Truncate table Transactions insert into Transactions (user_id, spend, transaction_date) values ('1', '65.56', '2023-11-18 13:49:42') insert into Transactions (user_id, spend, transaction_date) values ('1', '96.0', '2023-11-30 02:47:26') insert into Transactions (user_id, spend, transaction_date) values ('1', '7.44', '2023-11-02 12:15:23') insert into Transactions (user_id, spend, transaction_date) values ('1', '49.78', '2023-11-12 00:13:46') insert into Transactions (user_id, spend, transaction_date) values ('2', '40.89', '2023-11-21 04:39:15') insert into Transactions (user_id, spend, transaction_date) values ('2', '100.44', '2023-11-20 07:39:34') insert into Transactions (user_id, spend, transaction_date) values ('3', '37.33', '2023-11-03 06:22:02') insert into Transactions (user_id, spend, transaction_date) values ('3', '13.89', '2023-11-11 16:00:14') insert into Transactions (user_id, spend, transaction_date) values ('3', '7.0', '2023-11-29 22:32:36') Pandas Schema: data = [[1, 65.56, '2023-11-18 13:49:42'], [1, 96.0, '2023-11-30 02:47:26'], [1, 7.44, '2023-11-02 12:15:23'], [1, 49.78, '2023-11-12 00:13:46'], [2, 40.89, '2023-11-21 04:39:15'], [2, 100.44, '2023-11-20 07:39:34'], [3, 37.33, '2023-11-03 06:22:02'], [3, 13.89, '2023-11-11 16:00:14'], [3, 7.0, '2023-11-29 22:32:36']] transactions = pd.DataFrame(data, columns=['user_id', 'spend', 'transaction_date']).astype({ 'user_id': 'Int64', 'spend': 'float', # pandas does not have a fixed decimal; float is used for decimal numbers 'transaction_date': 'datetime64[ns]' # specifying datetime type }) #leetcodesolutions #datascience #sql


Tracks in this Playlist