Skip to content

Commit 4577a82

Browse files
authored
Add files via upload
1 parent 08ef1b3 commit 4577a82

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

Projects/ 8_Week_SQL_Challenge/Case_Study_2/Solution.sql

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ GROUP BY
158158
) AS subquery;
159159

160160
-- Question 7) For each customer, how many delivered pizzas had at least 1 change and how many had no changes?
161-
161+
SELECT
162+
*
163+
FROM
164+
pizza_runner.customer_orders;
162165

163166
WITH order_changes AS (
164167

@@ -199,7 +202,7 @@ GROUP BY
199202
) AS subquery
200203

201204
WHERE
202-
exclusions_with_extras != 0
205+
exclusions_with_extras != 0;
203206

204207

205208
-- Solution II
@@ -209,6 +212,63 @@ SELECT
209212
FROM
210213
pizza_runner.customer_orders
211214
WHERE
212-
exclusions IS NOT NULL AND extras IS NOT NULL
215+
exclusions IS NOT NULL AND extras IS NOT NULL;
216+
217+
-- Question 9) What was the total volume of pizzas ordered for each hour of the day?
218+
219+
SELECT
220+
*
221+
FROM
222+
pizza_runner.customer_orders;
223+
224+
225+
SELECT
226+
DATEPART(HOUR, order_time) AS order_hour,
227+
COUNT(pizza_id) AS count_of_pizza
228+
229+
FROM
230+
pizza_runner.customer_orders
231+
GROUP BY
232+
DATEPART(HOUR, order_time)
233+
ORDER BY
234+
order_hour ASC;
213235

214-
-- Question 9) What was the total volume of pizzas ordered for each hour of the day?
236+
-- Question 10)What was the volume of orders for each day of the week?
237+
238+
SELECT
239+
DATENAME(WEEKDAY, order_time) AS order_day,
240+
DATEPART(DAY, order_time) AS order_day_2,
241+
DATEPART(HOUR, order_time) AS order_hour,
242+
COUNT(pizza_id) AS count_of_pizza
243+
244+
FROM
245+
pizza_runner.customer_orders
246+
GROUP BY
247+
DATEPART(HOUR, order_time),
248+
DATENAME(WEEKDAY, order_time),
249+
DATEPART(DAY, order_time)
250+
ORDER BY
251+
order_day_2 ASC;
252+
253+
-- B. Runner and Customer Experience
254+
-- Question 1) How many runners signed up for each 1 week period? (i.e. week starts 2021-01-01)
255+
SELECT
256+
*
257+
FROM
258+
pizza_runner.runners;
259+
260+
WITH CTE AS (
261+
SELECT
262+
registration_date,
263+
DATEDIFF(WEEK, '2021-01-01', registration_date) + 1 AS week_number
264+
FROM
265+
pizza_runner.runners)
266+
SELECT
267+
week_number,
268+
COUNT(*) AS count_of_runners
269+
FROM
270+
CTE
271+
GROUP BY
272+
week_number
273+
ORDER BY
274+
week_number;

0 commit comments

Comments
 (0)