-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pizza Project.sql
97 lines (88 loc) · 2.37 KB
/
Pizza Project.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
# Criando banco dados
create database pizza_db;
use pizza_db;
# Importando tabela
create table big_table4
(
id int not null auto_increment,
order_id int not null,
pizza_id varchar(100),
quantity int,
order_date date,
order_time time,
unit_price varchar(10),
total_price varchar(10),
pizza_size varchar(5),
pizza_category varchar(30),
pizza_name varchar(150),
constraint pk_pizza primary key (id)
);
describe big_table4;
# Criando tabela Tratada
create table tab_geral (id int primary key auto_increment)
select
order_id,
pizza_id,
quantity,
order_date,
order_time,
cast(replace(unit_price,',','.') as decimal(4,2)) as unit_price,
cast(replace(total_price,',','.') as decimal(4,2)) as total_price,
pizza_size,
pizza_category,
pizza_name
from big_table4;
--------------------------------------------------------------------------
# Modelagem
create table dim_produto (id int primary key auto_increment)
select distinct
pizza_id,
pizza_name,
pizza_size,
pizza_category
from tab_geral;
select * from dim_produto;
create table dim_Tempo (id int primary key auto_increment)
select distinct
order_date,
order_time,
extract(year from order_date) as year,
extract(month from order_date) as month,
extract(week from order_date) as week,
extract(day from order_date) as day,
extract(hour from order_time) as hour
from tab_geral;
select * from dim_tempo;
create table ft_Pizza (id int primary key auto_increment)
select
pizza_id,
quantity,
unit_price,
total_price
from tab_geral;
create table ft_Pedido (id int primary key auto_increment)
select
order_id
quantity,
unit_price,
total_price
from tab_geral;
------------------------------------------------------------------------------
# View completo do projeto
create view v_pizza as
select distinct
dpo.pizza_name,
dpo.pizza_size,
order_date,
dayname(order_date) as day_name,
time_format(order_time, '%h pm') as _hour,
total_price,
round(count(quantity) * 4 / 4 * 1 ,0) as occupied_table,
round(count(quantity) * 4,0) as occupied_chair,
sum(quantity)
from ft_pizza fpi
join dim_tempo dte on fpi.id = dte.id
join dim_produto dpo on fpi.pizza_id = dpo.pizza_id
where order_date between '2015-01-01' and '2015-04-01'
group by 1,2,3,4,5,6
order by 3;