Uploaded by Jay Nagwani

Mercari MLE Assignment Submission

advertisement
Questions 1-1
select list.category_name, sum(list.price) as total_transaction
from listings as list
INNER join transactions as transact
on list.item_id = transact.item_id --inner joined listing and transaction table to access
transaction_date and price columne
where strftime("%Y-%m", transact.created) = "2019-09" --to get all transc=actions in september 2019
group by list.category_name --grouped by category_name to get summation value of transaction
values
order by total_transaction DESC --arrange in descending order with respect to total_transaction; -to get the highest total_transaction
limit 1;
ANS-290890
---Answer for Q.1-2---
with table1 AS --table 1 calculated the total number of users whose first and second listing are of
same category from total users with atleast two listings
(select count(*) c1
from
(select *, -- subquery to get rows with users whose first and second listing are of same category
rank() over(partition by lister_id order by created) as R, --to get the rank in created date for every
lister_id
lag(category_name) over(partition by lister_id order by created) as L -- one lag to match first and
second listing per user
from listings
where lister_id in (select lister_id -- subquery to return users with atleast two listings
from listings
group by lister_id
having count(lister_id) >= 2)) as x
where x.R=2 and x.L=x.category_name),
table2 AS --table 2 calculated the total number of users with atleast two listings
(select count(distinct lister_id) c2
from listings
where lister_id in (select lister_id
from listings
group by lister_id
having count(lister_id) >= 2))
Select round(cast(c1 as real)*100/cast(c2 as real), 1) percentage from table1, table2 -- query to
return percentage of required users using results from table1 and table2
ANS-34.1
--Answer for Q.1-3---column then category_id to get summation value of transaction values
select list.category_name, strftime("%Y-%m", transact.created) as month, avg(list.price) as
average_value_per_transaction
from listings list
inner join transactions transact --inner joined listing and transaction table to access transaction_date
and price
on list.item_id = transact.item_id
group by month, list.category_name --grouped by month and category_name to get monthly average
transactions for each category per month
order by month, category_name; --order by month and category_name to visualize better the
monthly averages for each category
e
Question 2:
In python
#stack initialization
St1= [ ]
St2 = []
#enqueue operation O(1) worst case
X = input()
St1.append(x)
#dequeue O(N+N)=O(N)
# worst time complexity where N is the number of elements because 2 for loop run for N time each
l1 = len(st1)
For i in range(l1):
St2.append(st1.pop(-1))
St2.pop(-1)
l2 = len(st2)
For i in range(l2):
St1.append(st2.pop(-1))
Download