Skip to content

Commit 0bd2366

Browse files
authored
Add files via upload
1 parent 00738b2 commit 0bd2366

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Information
2+
3+
---All column names in my view are underlined in red in SSMS
4+
---Or, using the menu: Edit -> IntelliSense -> Refresh Local Cache
5+
6+
/*To change the Prevent saving changes that require the table re-creation option, follow these steps:
7+
8+
Open SQL Server Management Studio.
9+
10+
On the Tools menu, click Options.
11+
12+
In the navigation pane of the Options window, click Designers.
13+
14+
Select or clear the Prevent saving changes that require the table re-creation check box, and then click OK. */
15+
16+
17+
USE pizza_runner;
18+
19+
SELECT
20+
*
21+
FROM
22+
pizza_runner.pizza_recipes;
23+
24+
-- Question 1) How many pizzas were ordered?
25+
26+
SELECT
27+
COUNT(order_id) AS count_of_pizzas
28+
FROM
29+
pizza_runner.customer_orders;
30+
--Answer = 14
31+
32+
-- Question 2) How many unique customer orders were made?
33+
34+
SELECT
35+
COUNT(DISTINCT A.customer_id) AS count_of_customer
36+
FROM
37+
pizza_runner.customer_orders AS A;
38+
--Answer = 5
39+
40+
41+
-- Question 3) How many successful orders were delivered by each runner?
42+
43+
SELECT
44+
runner_id,
45+
COUNT(*) AS succesful_orders
46+
FROM
47+
pizza_runner.runner_orders
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
CREATE DATABASE pizza_runner;
2+
USE pizza_runner;
3+
4+
CREATE SCHEMA pizza_runner;
5+
--SET search_path = pizza_runner;
6+
7+
DROP TABLE IF EXISTS pizza_runner.runners;
8+
CREATE TABLE pizza_runner.runners (
9+
"runner_id" INTEGER,
10+
"registration_date" DATE
11+
);
12+
13+
INSERT INTO pizza_runner.runners ("runner_id", "registration_date") VALUES
14+
(1, '2021-01-01'),
15+
(2, '2021-01-03'),
16+
(3, '2021-01-08'),
17+
(4, '2021-01-15');
18+
19+
DROP TABLE IF EXISTS pizza_runner.customer_orders;
20+
CREATE TABLE pizza_runner.customer_orders (
21+
"order_id" INTEGER,
22+
"customer_id" INTEGER,
23+
"pizza_id" INTEGER,
24+
"exclusions" VARCHAR(4),
25+
"extras" VARCHAR(4),
26+
"order_time" DATETIME
27+
);
28+
29+
INSERT INTO pizza_runner.customer_orders ("order_id", "customer_id", "pizza_id", "exclusions", "extras", "order_time") VALUES
30+
(1, 101, 1, '', '', '2020-01-01 18:05:02'),
31+
(2, 101, 1, '', '', '2020-01-01 19:00:52'),
32+
(3, 102, 1, '', '', '2020-01-02 23:51:23'),
33+
(3, 102, 2, '', NULL, '2020-01-02 23:51:23'),
34+
(4, 103, 1, '4', '', '2020-01-04 13:23:46'),
35+
(4, 103, 1, '4', '', '2020-01-04 13:23:46'),
36+
(4, 103, 2, '4', '', '2020-01-04 13:23:46'),
37+
(5, 104, 1, 'null', '1', '2020-01-08 21:00:29'),
38+
(6, 101, 2, 'null', 'null', '2020-01-08 21:03:13'),
39+
(7, 105, 2, 'null', '1', '2020-01-08 21:20:29'),
40+
(8, 102, 1, 'null', 'null', '2020-01-09 23:54:33'),
41+
(9, 103, 1, '4', '1, 5', '2020-01-10 11:22:59'),
42+
(10, 104, 1, 'null', 'null', '2020-01-11 18:34:49'),
43+
(10, 104, 1, '2, 6', '1, 4', '2020-01-11 18:34:49');
44+
45+
DROP TABLE IF EXISTS pizza_runner.runner_orders;
46+
CREATE TABLE pizza_runner.runner_orders (
47+
"order_id" INTEGER,
48+
"runner_id" INTEGER,
49+
"pickup_time" VARCHAR(19),
50+
"distance" VARCHAR(7),
51+
"duration" VARCHAR(10),
52+
"cancellation" VARCHAR(23)
53+
);
54+
55+
INSERT INTO pizza_runner.runner_orders ("order_id", "runner_id", "pickup_time", "distance", "duration", "cancellation") VALUES
56+
(1, 1, '2020-01-01 18:15:34', '20km', '32 minutes', ''),
57+
(2, 1, '2020-01-01 19:10:54', '20km', '27 minutes', ''),
58+
(3, 1, '2020-01-03 00:12:37', '13.4km', '20 mins', NULL),
59+
(4, 2, '2020-01-04 13:53:03', '23.4', '40', NULL),
60+
(5, 3, '2020-01-08 21:10:57', '10', '15', NULL),
61+
(6, 3, NULL, NULL, NULL, 'Restaurant Cancellation'),
62+
(7, 2, '2020-01-08 21:30:45', '25km', '25mins', NULL),
63+
(8, 2, '2020-01-10 00:15:02', '23.4 km', '15 minute', NULL),
64+
(9, 2, NULL, NULL, NULL, 'Customer Cancellation'),
65+
(10, 1, '2020-01-11 18:50:20', '10km', '10minutes', NULL);
66+
67+
DROP TABLE IF EXISTS pizza_runner.pizza_names;
68+
CREATE TABLE pizza_runner.pizza_names (
69+
"pizza_id" INTEGER,
70+
"pizza_name" TEXT
71+
);
72+
73+
INSERT INTO pizza_runner.pizza_names ("pizza_id", "pizza_name") VALUES
74+
(1, 'Meatlovers'),
75+
(2, 'Vegetarian');
76+
77+
DROP TABLE IF EXISTS pizza_runner.pizza_recipes;
78+
CREATE TABLE pizza_runner.pizza_recipes (
79+
"pizza_id" INTEGER,
80+
"toppings" TEXT
81+
);
82+
83+
INSERT INTO pizza_runner.pizza_recipes ("pizza_id", "toppings") VALUES
84+
(1, '1, 2, 3, 4, 5, 6, 8, 10'),
85+
(2, '4, 6, 7, 9, 11, 12');
86+
87+
DROP TABLE IF EXISTS pizza_runner.pizza_toppings;
88+
CREATE TABLE pizza_runner.pizza_toppings (
89+
"topping_id" INTEGER,
90+
"topping_name" TEXT
91+
);
92+
93+
INSERT INTO pizza_runner.pizza_toppings ("topping_id", "topping_name") VALUES
94+
(1, 'Bacon'),
95+
(2, 'BBQ Sauce'),
96+
(3, 'Beef'),
97+
(4, 'Cheese'),
98+
(5, 'Chicken'),
99+
(6, 'Mushrooms'),
100+
(7, 'Onions'),
101+
(8, 'Pepperoni'),
102+
(9, 'Peppers'),
103+
(10, 'Salami'),
104+
(11, 'Tomatoes'),
105+
(12, 'Tomato Sauce');

0 commit comments

Comments
 (0)