-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-1.sql
More file actions
35 lines (31 loc) · 674 Bytes
/
6-1.sql
File metadata and controls
35 lines (31 loc) · 674 Bytes
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
-- checkout client data
select *
from clients;
-- how many rows do we have?
-- 35,749
select count(1)
from sales_all_years
-- inner join from sales
-- 35,749
select count(1)
from sales_all_years s
join clients c on s.companyname = c.name
-- Add details about clients for a more comprehensive answer
select
c.marketcaplabel,
c.marketcapamount,
c.name,
c.ipoyear,
c.symbol,
count(distinct s.orderid) OrderCount,
sum(s.saleamount) as TotalSales
from sales_all_years s
join clients c on s.companyname = c.name
group by
c.marketcaplabel,
c.marketcapamount,
c.name,
c.ipoyear,
c.symbol
order by
c.marketcapamount desc