Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 0 database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use master
go
drop database if exists CoffeeDB
go
create database CoffeeDB
go
use CoffeeDB
22 changes: 22 additions & 0 deletions 1 table.sql
Original file line number Diff line number Diff line change
@@ -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 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'))

)
25 changes: 25 additions & 0 deletions 3 sample data.sql
Original file line number Diff line number Diff line change
@@ -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'
22 changes: 22 additions & 0 deletions 4 reports.sql
Original file line number Diff line number Diff line change
@@ -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