-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
43 lines (37 loc) · 1.02 KB
/
Copy pathqueries.sql
File metadata and controls
43 lines (37 loc) · 1.02 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
--Savana Hughes & David Abushlaih
--Team3
--AVG_Business_Order_Value:
select
business_id,
sum(gross_revenue)/count(distinct order_id) as AVG_Business_Order_Value
from business_order_lineitem
group by 1;
--Total Business Revenue
select
business_id,
sum(gross_revenue) as Total_Business_Revenue
from business_order_lineitem
group by 1
ORDER BY 2 ASC;
--AVG Monthly Revenue
select
boi.business_id,
count(distinct date_trunc('year', bo.created_at)) as number_years,
sum(gross_revenue)/count(distinct date_trunc('year', bo.created_at))/12 as Avg_Monthly_Revenue
from business_order_lineitem as boi
Left join business_order as bo
on bo.business_id = boi.business_id and
Bo.order_id = boi.order_id
group by 1
ORDER BY 3 ASC;
--Revenue By Year
select
boi.business_id,
date_part('year', bo.created_at) as date_year,
sum(gross_revenue) as Avg_Yearly_Revenue
from business_order_lineitem as boi
Left join business_order as bo
on bo.business_id = boi.business_id and
Bo.order_id = boi.order_id
group by 1, 2
ORDER BY 2 ASC, 3 ASC;