Leetcode HARD 2474 - Customers with Strictly Increasing Purchase -Explained by Everyday Data Science

Опубликовано: 21 Октябрь 2024
на канале: Everyday Data Science
333
13

Question: https://leetcode.com/problems/custome...

SQL Schema:
Create table If Not Exists Orders (order_id int, customer_id int, order_date date, price int)
Truncate table Orders
insert into Orders (order_id, customer_id, order_date, price) values ('1', '1', '2019-07-01', '1100')
insert into Orders (order_id, customer_id, order_date, price) values ('2', '1', '2019-11-01', '1200')
insert into Orders (order_id, customer_id, order_date, price) values ('3', '1', '2020-05-26', '3000')
insert into Orders (order_id, customer_id, order_date, price) values ('4', '1', '2021-08-31', '3100')
insert into Orders (order_id, customer_id, order_date, price) values ('5', '1', '2022-12-07', '4700')
insert into Orders (order_id, customer_id, order_date, price) values ('6', '2', '2015-01-01', '700')
insert into Orders (order_id, customer_id, order_date, price) values ('7', '2', '2017-11-07', '1000')
insert into Orders (order_id, customer_id, order_date, price) values ('8', '3', '2017-01-01', '900')
insert into Orders (order_id, customer_id, order_date, price) values ('9', '3', '2018-11-07', '900')

Pandas Schema:
data = [[1, 1, '2019-07-01', 1100], [2, 1, '2019-11-01', 1200], [3, 1, '2020-05-26', 3000], [4, 1, '2021-08-31', 3100], [5, 1, '2022-12-07', 4700], [6, 2, '2015-01-01', 700], [7, 2, '2017-11-07', 1000], [8, 3, '2017-01-01', 900], [9, 3, '2018-11-07', 900]]
orders = pd.DataFrame(data, columns=['order_id', 'customer_id', 'order_date', 'price']).astype({'order_id':'Int64', 'customer_id':'Int64', 'order_date':'datetime64[ns]', 'price':'Int64'})

#datascience #mysqltutorials #leetcodesolutions