forked from ReynaldoMR3/clases_datamex1019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries(w2_d2).sql
91 lines (48 loc) · 1.45 KB
/
queries(w2_d2).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
select stores.stor_name as store,
count(distinct(ord_num)) as orders,
count(title_id) as items, sum(qty) as qty
from publications.sales sales
inner join publications.stores stores
on stores.stor_id=sales.stor_id
group by store;
select store, items/orders as avgitems,
qty/items avgqty
from
(select stores.stor_name as store,
count(distinct(ord_num)) as orders,
count(title_id) as items, sum(qty) as qty
from publications.sales sales
inner join publications.stores stores
on stores.stor_id=sales.stor_id
group by store) averages
;
select store, ord_num as orderNumber,
title, sales.qty as qty,
price, type, (sales.qty*price) as revenue
from
(select stores.stor_id as storeID,
stores.stor_name as store,
count(distinct(ord_num)) as orders,
count(title_id) as items,
sum(qty) as qty
from publications.sales sales
inner join publications.stores stores
on stores.stor_id=sales.stor_id
group by storeID, store
) summary
inner join publications.sales sales
on summary.storeID=sales.stor_id
inner join publications.titles
on sales.title_id=titles.title_id
where items/orders>1
create temporary table publications.store_sales_summary
select stores.stor_id as storeID, stores.stor_name as store,
count(distinct(ord_num)) as orders,
count(title_id) as items, sum(qty) as qty
from publications.sales sales
inner join publications.stores stores
on stores.stor_id=sales.stor_id
group by storeID, store
;
select *
from publications.store_sales_summary;