You are on page 1of 4

Database Lab Task

Name: Mahak Imran

Rollno.: 22101001-051

Q#1

List all Menu items

create table menuItems(

itemId int primary key,

name varchar(20),

price int,

category varchar(20)

);

insert into menuItems values (21,'fries',280,'apetizer');

insert into menuItems values (43,'soup',360,'apetizer');

insert into menuItems values (34,'butter chicken',1200,'main course');

insert into menuItems values (71,'rice',540,'main course');

insert into menuItems values (56,'lemon soda',120,'drink');

select *From menuItems;

Q#2
Find total number of orders for each customer

select customer.name, count (orderr.orderId) AS totalorders

from customer

left join

orderr on customer.customerId=orderr.customerId

group by customer.customerId,customer.name;

Q#3

List menuitems in a specific category

select *from menuItems where category= 'main course';

Q#4

Calculate total revenue for a specific date

select sum (orderDetails.quantity* menuItems.price) AS totalRevenue

from orderr

join orderDetails on orderr.orderId = orderDetails.orderId

join menuitems on orderDetails.itemId = menuItems.itemId


where orderr.orderdate = '2023-03-04'

Q#5

Update price of a specific menu item

update menuitems

set price=1500

where name='butter chicken';

select *from menuitems;

Q#6

Get list of orders with menuitems

select orderr.orderId, customer.name AS customerName, orderr.orderdate, menuitems.name AS


menuitem, orderDetails.quantity

from orderr
join customer on orderr.customerId = customer.customerId

join orderDetails on orderr.orderId = orderDetails.orderId

join menuitems on orderDetails.itemId = menuitems.itemId;

Q#7

Delete a menu item that has been never ordered

delete from menuitems

where itemId not in (select distinct menuitems.itemId from menuitems left join orderDetails on
menuitems.itemId = orderDetails.itemId where orderDetails.itemId is NULL);

You might also like