Add sales report scripts and results

This commit is contained in:
2024-11-17 14:47:44 +01:00
parent 70f6458e03
commit aac9358de5
4 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
-- sales report - task 1
-- changes:
-- interpreted quantity as the number of ordered items, because I assumed that Little lemon wants
-- orders à la carte instead of fixed menus
drop view if exists OrdersView;
create view OrdersView as
select
O.OrderID,
count(OI.MenuItemID) as Quantity,
O.BillAmount as Cost
from Orders as O
inner join OrderItems as OI on O.OrderID = OI.OrderID
group by O.OrderID
having Quantity > 2;

View File

@@ -0,0 +1,47 @@
-- sales report - task 2
-- changes:
-- removed menu name, because I assumed that Little lemon wants orders à la carte instead of fixed menus
-- changed cost cutoff from 150.00 to 75.00, because I wanted more than one test result
with
GroupedOrderItems as (
select
OI.OrderID,
MI.Category,
concat(MI.Name, " (", count(OI.OrderItemID), "x)") as Item
from OrderItems as OI
inner join MenuItems as MI on OI.MenuItemID = MI.MenuItemID
group by OI.OrderID, MI.Category, OI.MenuItemID
),
MainOrderItems as (
select
OrderID,
group_concat(Item separator '\n') as Items
from GroupedOrderItems
where Category = "Main"
group by OrderID
),
StarterOrderItems as (
select
OrderID,
group_concat(Item separator '\n') as Items
from GroupedOrderItems
where Category = "Starter"
group by OrderID
)
select
C.CustomerID,
concat(C.FirstName, " ", C.LastName) as FullName,
O.OrderID,
O.BillAmount as Cost,
coalesce(MOI.Items, "") as Mains,
coalesce(SOI.Items, "") as Starters
from Orders as O
inner join Bookings as B on O.BookingID = B.BookingID
inner join Customers as C on B.CustomerID = C.CustomerID
left join MainOrderItems as MOI on O.OrderID = MOI.OrderID
left join StarterOrderItems as SOI on O.OrderID = SOI.OrderID
where O.BillAmount > 75.00
group by O.OrderID;

View File

@@ -0,0 +1,11 @@
-- sales report - task 3
-- changes:
-- replaced menu name with menu item name, because I assumed that Little lemon wants orders à la carte
-- instead of fixed menus
select
MI.Name,
count(OI.OrderItemID) as OrderQuantity
from MenuItems as MI
inner join OrderItems as OI on MI.MenuItemID = OI.MenuItemID
group by OI.MenuItemID
having OrderQuantity > 2;

View File

@@ -0,0 +1,40 @@
# Task 1
> source ./create_orders_view.sql
> select * from OrdersView;
+---------+----------+--------+
| OrderID | Quantity | Cost |
+---------+----------+--------+
| 1 | 9 | 82.50 |
| 2 | 3 | 28.00 |
| 3 | 3 | 31.00 |
| 4 | 3 | 29.00 |
| 6 | 15 | 150.50 |
+---------+----------+--------+
# Task 2
> source ./get_expensive_orders.sql
+------------+---------------+---------+--------+-----------------------+--------------------------+
| CustomerID | FullName | OrderID | Cost | Mains | Starters |
+------------+---------------+---------+--------+-----------------------+--------------------------+
| 3 | Li Wei Zhang | 1 | 82.50 | Gigantes Plaki (2x) | Grilled Artichokes (1x) |
| | | | | Pasta alla Norma (1x) | Lentil Soup (1x) |
| | | | | | Humus Plate (1x) |
| 5 | Ivanov Petrov | 6 | 150.50 | Minestrone (2x) | Lentil Soup (2x) |
| | | | | Gigantes Plaki (2x) | Eggplant Bruschetta (1x) |
| | | | | Moussaka (1x) | Humus Plate (1x) |
| | | | | | Grilled Artichokes (1x) |
+------------+---------------+---------+--------+-----------------------+--------------------------+
# Task 3
> source ./get_popular_menu_items.sql
+--------------------+---------------+
| Name | OrderQuantity |
+--------------------+---------------+
| Lentil Soup | 4 |
| Humus Plate | 3 |
| Gigantes Plaki | 5 |
| Minestrone | 3 |
| Fruit Salad | 3 |
| Grilled Mango | 3 |
| Grilled Waterlemon | 3 |
+--------------------+---------------+