-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigbasket_sql.sql
More file actions
73 lines (62 loc) · 1.85 KB
/
bigbasket_sql.sql
File metadata and controls
73 lines (62 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- Analysis of Price, Discount, and Category
use code_it;
CREATE TABLE bigbasket_cln (
id INT AUTO_INCREMENT PRIMARY KEY,
Product_Name VARCHAR(255),
Price FLOAT,
Discount FLOAT,
Category VARCHAR(100)
);
-- Average Price by Category
SELECT Category, round(AVG(Price), 2) AS Average_price
FROM bigbasket_cln
GROUP BY Category
order by Average_price desc;
-- Highest price by Category
SELECT Category, Max(Price) AS Highest_price
FROM bigbasket_cln
GROUP BY Category
order by Highest_price desc;
-- Lowest price by category
select Category, MIN(Price) as Lowest_price
from bigbasket_cln
group by Category
order by Lowest_price;
-- Average discount by category
SELECT Category, round(AVG(Discount), 2) AS Average_discount
FROM bigbasket_cln
GROUP BY Category
order by Average_discount desc;
-- Highest discount by category
SELECT Category, Max(Discount) AS Highest_discount
FROM bigbasket_cln
GROUP BY Category
order by Highest_discount desc;
select * from bigbasket_cln;
-- Count the products in each category
SELECT Category, count(*) Total_products
from bigbasket_cln
group by Category
order by Total_products desc;
-- Top 10 most expensive Product
SELECT distinct(Product_Name), Price
from bigbasket_cln
order by price desc
limit 10;
-- Top 10 most discounted Product
SELECT distinct(Product_Name), Discount
from bigbasket_cln
order by Discount desc
limit 10;
-- Top 3 most expensive Product in each Category
SELECT Product_Name, Category, Price
from (select distinct(Product_Name), Category, Price,
RANK() OVER (partition by Category ORDER BY Price desc) as rnk
from bigbasket_cln) ranked
where rnk <= 3;
-- Top 3 most discounted Product in each Category
SELECT Product_Name, Category, Discount
from (select distinct(Product_Name), Category, Discount,
RANK() OVER (partition by Category ORDER BY Price desc) as rnk
from bigbasket_cln) ranked
where rnk <= 3;