-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE commerce Analysis By Hemil Shah.sql
278 lines (73 loc) · 3.33 KB
/
E commerce Analysis By Hemil Shah.sql
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
select * from customers
where customer_state not in ('MG','SP','SC')
select * from orders
where order_status ='canceled'
select * from payments
where payment_type='UPI' and payment_value>= 500 and payment_installments =1
select * from payments
where payment_value between 150 and 200
order by payment_value
select customer_city from customers
where customer_city like 'r%'
select * from payments
where payment_installments = 1
order by payment_value desc
select top 5 * from payments
select round(sum(payment_value),2) as 'Total Payments'from payments
select avg(payment_value) as 'Average Payment value' from payments
select count(customer_id) as 'Total Customers' from customers
select count(distinct(customer_city)) as 'Total Cities' from customers
select seller_city,len(trim(seller_city)) from sellers
select upper(seller_city) from sellers
select seller_city,replace(seller_city,'CURITIBA','AHMEDABAD') as 'replaced city' from sellers
select seller_city +'-' +seller_state from sellers
select CONCAT(seller_city ,'-', seller_state) as 'City and state' from sellers
SELECT
order_delivered_customer_date,
DAY(order_delivered_customer_date) AS 'Day',
MONTH(order_delivered_customer_date) AS 'MonthNumber',
FORMAT(order_delivered_customer_date, 'MMMM') AS 'MonthName',
YEAR(order_delivered_customer_date) AS 'Year'
FROM
orders;
select distinct(year(order_delivered_customer_date)) as 'year'
from orders
SELECT
DATEDIFF(day, orders.order_delivered_customer_date, orders.order_estimated_delivery_date) AS 'DifferenceInDays'
FROM
orders;
select payment_value,ceiling(payment_value) as 'upper bound'from payments
select * from orders
where orders.order_delivered_customer_date is null
select upper(orders.order_status) as 'order status'
,count(orders.order_status) as 'Count of Order Status'
from orders
group by orders.order_status
order by count(orders.order_status) desc
select payment_type,round(avg(payments.payment_value),2) as 'Avg payment by payment method'
from payments
where payment_installments <= 4
group by payment_type
select payment_type,round(avg(payments.payment_value),2) as 'Avg payment by payment method'
from payments
where payment_value > 100
group by payment_type
select customers.customer_id,order_status
from customers join orders
on customers.customer_id = orders.customer_id
where order_status = 'shipped'
select year(orders.order_delivered_customer_date) as 'Year',
(round(sum(payments.payment_value),1)) as 'Total payment per year ',
(round(sum(payments.payment_value),1)*100/(select sum(payments.payment_value) from payments)) as 'Percentage from Total payment per year '
from orders join payments
on payments.order_id = orders.order_id
group by year(orders.order_delivered_customer_date)
order by year(orders.order_delivered_customer_date)
select Top 5 product_category,sum(payment_value) as 'Total Payment Value',
(sum(payment_value)*100/(select sum(payments.payment_value) from payments)) as 'Percentage from Total Payment Value'
from products join order_items
on order_items.product_id = products.product_id
join payments
on order_items.order_id = payments.order_id
group by product_category
order by sum(payment_value) desc