-
Notifications
You must be signed in to change notification settings - Fork 1
/
SQL Query - SuperTaste Pizza.sql
69 lines (55 loc) · 2.6 KB
/
SQL Query - SuperTaste Pizza.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
--For an in-office staff with id number STAFF00600, print his/her first name, last name and hourly payment rate.
SELECT FirstName, LastName, PaymentRate
FROM InStoreStaff
WHERE StaffID = 'STAFF00600';
--List all the ingredient details of a menu item named pizza.
SELECT I.*
FROM Ingredient I, MenuItem M, QMenuIngredient QMI
WHERE I.IngCode = QMI.IngCode AND
M.ItemCode = QMI.ItemCode AND
M.ItemName = 'Pizza';
--List all the shift details of a delivery staff with first name Mir and last name Danish between date 01/02/2021 and 28/02/2021.
SELECT DS.*
FROM DriverShift DS, DriverStaff D
WHERE DS.StaffID = D.StaffID AND
D.FirstName = 'Mir' AND
D.LastName = 'Danish' AND
DS.StartDateTime BETWEEN '2021-02-01' AND '2021-02-28';
--List all the order details of the orders that are made by a walk-in customer with first name Michael and last name Stuart between date 01/01/2021 and 31/01/2021.
SELECT O.*, W.WalkInTime
FROM Orders O, Customer C, WalkinOrder W
WHERE O.OrderNo = W.OrderNo AND
O.CustomerID = C.CustomerID AND
c.FirstName = 'Michael'AND
c.LastName = 'Stuart' AND
W.WalkInTime BETWEEN '2021-02-01' AND '2021-02-28';
--List all the order details of the orders that are taken by an in-office staff with first name Michelle and last name Humberson between date 01/02/2021 and 28/02/2021.
SELECT O.*
FROM Orders O, InStoreStaff I
WHERE O.StaffID = I.StaffID AND
I.FirstName = 'Michelle' AND
I.LastName = 'Humberson' AND
O.OrderDateTime BETWEEN '2021-02-01' AND '2021-02-28';
--Print the salary paid to a delivery staff with first name Liam and last name Stanley in current month. Note the current month is the current that is decided by the system.
SELECT S.GrossSalary
FROM DriverStaff D, DriverShift DS, DriverPay S
WHERE S.SalaryID = DS.SalaryID AND
DS.StaffID = D.StaffID AND
D.FirstName = 'Liam' AND
D.LastName = 'Stanley' AND
DATEPART(MONTH, (S.SalaryEndDate)) = MONTH(GETDATE());
--List the name of the menu item that is mostly ordered in current year.
SELECT m.ItemCode, m.ItemName, SUM(QMO.quantity) AS timesOrdered
FROM MenuItem m, QMenuOrder QMO, Orders o
WHERE m.ItemCode = QMO.ItemCode AND
o.OrderNo = QMO.OrderNo AND
DATEPART(YEAR, (o.OrderDateTime)) = YEAR(GETDATE())
GROUP BY m.ItemCode, m.ItemName
HAVING SUM(QMO.quantity) >= ALL
(SELECT SUM(QMO2.quantity)
FROM MenuItem m2, QMenuOrder QMO2, Orders o2
WHERE m2.ItemCode = QMO2.ItemCode AND
o2.OrderNo = QMO2.OrderNo AND
DATEPART(YEAR, (o2.OrderDateTime)) = YEAR(GETDATE())
GROUP BY m2.ItemCode, m2.ItemName
);