From 26a2936ddf2e29e8b13cdf1d270a589dbf6da2cd Mon Sep 17 00:00:00 2001 From: hanoch padwa Date: Fri, 22 Aug 2025 13:41:26 +0100 Subject: [PATCH 1/2] added the files you asked for your coffee kiosk --- 0 database.sql | 7 +++++++ 1 table.sql | 22 ++++++++++++++++++++++ 3 sample data.sql | 25 +++++++++++++++++++++++++ 4 reports.sql | 22 ++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 0 database.sql create mode 100644 1 table.sql create mode 100644 3 sample data.sql create mode 100644 4 reports.sql diff --git a/0 database.sql b/0 database.sql new file mode 100644 index 0000000..6a5a8ef --- /dev/null +++ b/0 database.sql @@ -0,0 +1,7 @@ +use master +go +drop database if exists CoffeeDB +go +create database CoffeeDB +go +use CoffeeDB \ No newline at end of file diff --git a/1 table.sql b/1 table.sql new file mode 100644 index 0000000..39dd3d4 --- /dev/null +++ b/1 table.sql @@ -0,0 +1,22 @@ +/* +PurchaseID primary key int not null unique +PurchaseTime datetime not before today not null not blank +PurchaseItem varchar(30) not null not blank +PriceEach decimal(5,2) not null not negative +Quantity int not null +TotalPrice decimal(5,2) not null +PaymentMethod varchar(5) must be either cash or card not null not blank +*/ + +drop table if exists CoffeeKiosk +go +create table dbo.CoffeeKiosk( + PurchaseId int not null identity primary key, + PurchaseDate date not null constraint CofeeKiosk_Purchase_time_cannot_be_blank check(PurchaseDate <> ''), + constraint CoffeeKiosk_Purchase_time_cannot_be_after_current_date check(PurchaseDate <= getdate()), + PurchaseItem varchar(30) not null constraint CoffeeKiosk_Purchase_item_cannot_be_blank check(PurchaseItem <> ''), + PriceEach decimal(5,2) not null constraint CoffeeKiosk_price_each_cannot_be_a_negative_number check(PriceEach >= 0), + Quantity int not null, + TotalPrice as PriceEach * Quantity persisted, + PaymentMethod varchar(5) not null constraint CoffeKiosk_Payment_method_must_be_either_cash_or_card check(PaymentMethod in('cash', 'card')) +) \ No newline at end of file diff --git a/3 sample data.sql b/3 sample data.sql new file mode 100644 index 0000000..09238f8 --- /dev/null +++ b/3 sample data.sql @@ -0,0 +1,25 @@ +delete coffeeKiosk + +insert CoffeeKiosk(PurchaseDate, PurchaseItem, PriceEach, Quantity, PaymentMethod) +select '2025-04-12', 'Cappuccino', 3.50, 2, 'card' +union select '2024-01-15', 'Latte', 3.20, 1, 'cash' +union select '2022-12-25', 'Espresso', 2.50, 2, 'card' +union select '2020-03-06', 'Mocha', 3.80, 1, 'card' +union select '2019-02-10', 'Americano', 2.80, 1, 'cash' +union select '2009-10-15', 'Cappuccino', 3.50, 3, 'card' +union select '2010-07-03', 'Croissant', 2.00, 2, 'cash' +union select '2011-01-12', 'Flat White', 3.00, 1, 'card' +union select '2012-02-22', 'Latte', 3.20, 2, 'cash' +union select '2025-08-21', 'Iced Coffee', 3.60, 1, 'card' +union select '2024-03-09', 'Cappuccino', 3.50, 1, 'cash' +union select '2025-01-20', 'Espresso', 2.50, 4, 'card' +union select '2023-05-18', 'Sandwich', 4.50, 1, 'card' +union select '2024-09-16', 'Mocha', 3.80, 2, 'cash' +union select '2024-06-13', 'Latte', 3.20, 1, 'card' +union select '2025-03-09', 'Tea', 2.00, 2, 'cash' +union select '2025-04-11', 'Cappuccino', 3.50, 1, 'card' +union select '2025-04-12', 'Brownie', 2.20, 3, 'cash' +union select '2025-04-12', 'Espresso', 2.50, 1, 'card' +union select '2025-04-12', 'Iced Latte', 3.70, 2, 'card' +union select '2025-04-12', 'Espresso', 2.50, -1, 'card' +union select '2025-04-12', 'Iced Latte', 3.70, -2, 'card' diff --git a/4 reports.sql b/4 reports.sql new file mode 100644 index 0000000..0cb1ff0 --- /dev/null +++ b/4 reports.sql @@ -0,0 +1,22 @@ +--Daily revenue: How much money did we make today? +select TodaysRevenue = sum(TotalPrice), day = c.PurchaseDate +from CoffeeKiosk c +group by c.PurchaseDate +order by c.PurchaseDate desc + +--Top products: What are the top 5 products by sales volume or revenue in the last month? +select top 5 AmountSold = count(c.PurchaseItem), Revenue = sum(c.TotalPrice), c.PurchaseItem +from CoffeeKiosk c +where c.PurchaseDate between datefromparts(year(getdate()), month(getdate()) - 1, day(getdate())) and datefromparts(year(getdate()), month(getdate()), day(getdate())) +group by c.PurchaseItem +order by count(c.PurchaseItem) desc, sum(c.TotalPrice) desc + + +--Payment reconciliation: How much came in by cash vs card each day? +select Sum = sum(c.TotalPrice), c.PaymentMethod +from CoffeeKiosk c +group by c.PaymentMethod + + + + From 47edda2a4876132fd01145937282683777abd142 Mon Sep 17 00:00:00 2001 From: hanoch padwa Date: Fri, 22 Aug 2025 13:47:16 +0100 Subject: [PATCH 2/2] i removed the string comparison from the date data type --- 1 table.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1 table.sql b/1 table.sql index 39dd3d4..679a0be 100644 --- a/1 table.sql +++ b/1 table.sql @@ -12,11 +12,11 @@ drop table if exists CoffeeKiosk go create table dbo.CoffeeKiosk( PurchaseId int not null identity primary key, - PurchaseDate date not null constraint CofeeKiosk_Purchase_time_cannot_be_blank check(PurchaseDate <> ''), - constraint CoffeeKiosk_Purchase_time_cannot_be_after_current_date check(PurchaseDate <= getdate()), + PurchaseDate date not null constraint CoffeeKiosk_Purchase_time_cannot_be_after_current_date check(PurchaseDate <= getdate()), PurchaseItem varchar(30) not null constraint CoffeeKiosk_Purchase_item_cannot_be_blank check(PurchaseItem <> ''), PriceEach decimal(5,2) not null constraint CoffeeKiosk_price_each_cannot_be_a_negative_number check(PriceEach >= 0), Quantity int not null, TotalPrice as PriceEach * Quantity persisted, PaymentMethod varchar(5) not null constraint CoffeKiosk_Payment_method_must_be_either_cash_or_card check(PaymentMethod in('cash', 'card')) -) \ No newline at end of file + +)