Skip to content

Commit 2f3d2b3

Browse files
committed
Queries added
1 parent 5e49c41 commit 2f3d2b3

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

queries.sql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,79 @@ order by
3939
1;
4040

4141

42+
43+
\! echo "============================================="
44+
\! echo "Cost per month"
45+
\! echo "============================================="
46+
select date_trunc('month', c.invoice_date) as month, sum(c.cost) as monthly_cost
47+
from cost c
48+
group by month
49+
order by month;
50+
51+
\! echo "============================================="
52+
\! echo "Cost per month trend per project"
53+
\! echo "============================================="
54+
select p.project_name, date_trunc('month', c.invoice_date) as month, sum(c.cost) as total_cost
55+
from cost c
56+
join project p on c.project_id = p.project_id
57+
group by p.project_name, month
58+
order by p.project_name, month;
59+
60+
61+
\! echo "============================================="
62+
\! echo "Cost per month trend per service"
63+
\! echo "============================================="
64+
select s.service_name, date_trunc('month', c.invoice_date) as month, sum(c.cost) as service_cost
65+
from cost c
66+
join service s on c.service_id = s.service_id
67+
group by s.service_name, month
68+
order by s.service_name, month;
69+
70+
71+
\! echo "============================================="
72+
\! echo "Cost per month trend per sku"
73+
\! echo "============================================="
74+
select sku.sku_name, date_trunc('month', c.invoice_date) as month, sum(c.usage_amount) as total_usage, sum(c.cost) as total_cost
75+
from cost c
76+
join sku on c.sku_id = sku.sku_id
77+
group by sku.sku_name, month
78+
order by sku.sku_name, month;
79+
80+
81+
\! echo "============================================="
82+
\! echo "Cost per month trend for specific project"
83+
\! echo "============================================="
84+
select s.service_name, date_trunc('month', c.invoice_date) as month, sum(c.cost) as total_cost
85+
from cost c
86+
join service s on c.service_id = s.service_id
87+
where c.project_id = 'container-solutions-finance'
88+
group by s.service_name, month
89+
order by s.service_name, month;
90+
91+
92+
93+
94+
95+
\! echo "============================================="
96+
\! echo "Savings through credits"
97+
\! echo "============================================="
98+
select credit_type, sum(c.cost) as saved_cost
99+
from cost c
100+
where c.credit_type is not null
101+
group by credit_type
102+
order by saved_cost desc;
103+
104+
105+
\! echo "============================================="
106+
\! echo "Usage and costs of skus"
107+
\! echo "============================================="
108+
select sku.sku_name, sum(c.usage_amount) as total_usage, sum(c.cost) as total_cost
109+
from cost c
110+
join sku on c.sku_id = sku.sku_id
111+
group by sku.sku_name
112+
order by total_cost desc;
113+
114+
42115
\! echo "============================================="
43116
\! echo "Project ordered by cost > x"
44117
\! echo "============================================="

0 commit comments

Comments
 (0)