Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 03 #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions day03/JOIN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Databricks notebook source
select
t1.*,
t2.vlPreco
from silver.pizza_query.item_pedido as t1
left join silver.pizza_query.produto as t2
on t1.descItem = t2.descItem

-- COMMAND ----------

select
t1.idPedido,
sum(t2.vlPreco) as vl_pedido
from silver.pizza_query.item_pedido as t1

left join silver.pizza_query.produto as t2
on t1.descItem = t2.descItem

where t1.descTipoItem<> 'bebida'

GROUP by t1.idPedido

-- COMMAND ----------


183 changes: 183 additions & 0 deletions day03/PIZZA_SELECT.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
-- Databricks notebook source
select
*
from silver.pizza_query.item_pedido

-- COMMAND ----------

SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'borda'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1

-- COMMAND ----------

SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'massa'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1

-- COMMAND ----------

SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%ingrediente%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 5

-- COMMAND ----------

SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%queijo%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1

-- COMMAND ----------

SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'bebida'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1

-- COMMAND ----------

--Descobrindo a pizza perfeita
SELECT
*
FROM(

(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'borda'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'massa'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%ingrediente%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 5)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%queijo%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'bebida'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)
) AS t1

LEFT JOIN silver.pizza_query.produto AS t2
ON t1.descItem = t2.descItem

-- COMMAND ----------

--Descobrindo a pizza perfeita
SELECT
sum(vlPreco)
FROM(

(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'borda'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'massa'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%ingrediente%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 5)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem LIKE '%queijo%'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)

UNION ALL
(SELECT descItem,
count(*) as qtdPedido
FROM silver.pizza_query.item_pedido
WHERE descTipoItem = 'bebida'

GROUP BY descItem
ORDER BY qtdPedido DESC
LIMIT 1)
) AS t1

LEFT JOIN silver.pizza_query.produto AS t2
ON t1.descItem = t2.descItem

-- COMMAND ----------