Introduction To Database Systems
Introduction To Database Systems
- SalesPerson Instance :
Sales_Last_Nam Sales_First_Nam
Sales_ID e e
1 SAL001 Glenn Barry
2 SAL002 Torres Santino
3 SAL003 Simorangkir Gerry
Degree : 3; Cardinality : 3; Candidate key(s) : Sales_ID; Alternate key(s) : -
b. How long Customer gets the car back after service completed from the Date
Received? (or called Service Duration). Show Service_Ticket_ID, Car_ID,
Customer_ID, Service Duration and order by Service Duration on
descending order
select Service_Ticket_ID, Car_ID, Customer_ID, Service_Duration =
Convert(varchar, DATEDIFF(DAY, Date_Received,Date_Returned)) + ' Days'
from Service_Ticket
order by Service_Duration DESC
c. List Part_Used_ID and the Price with currency symbol “USD” (for example :
100 USD)
select Parts_Used_ID, Price = Convert(varchar,Price) + ' USD'
from Parts_Used
b. Find number of Car in each Model. List on ascending order by the Model
(5%) Output : Model | Car_Count
select [Car_Count] = count(Model), Model
from Car
group by Model
c. For each Customer with more than 1 Service Order, find Car_ID and sum of
their Orders (10%) Output : Customer_ID | My Service Order Count
select Customer.Customer_ID, [My Service Order Count] =
count(Service_Ticket_ID)
from Customer join Service_Ticket on Customer.Customer_ID =
Service_Ticket.Customer_ID
group by Customer.Customer_ID
having count(Customer.Customer_ID) > 1
use Car_Dealership
select *
from Service_Ticket
--5b.
select Service_Ticket_ID, Car_ID, Customer_ID, Service_Duration =
Convert(varchar, DATEDIFF(DAY, Date_Received,Date_Returned)) + ' Days'
from Service_Ticket
order by Service_Duration DESC
--5c.
select Parts_Used_ID, Price = Convert(varchar,Price) + ' USD'
from Parts_Used
--6a.
select [Total Parts] = count(Parts_ID), Description
from Parts
group by Description
--6b.
select [Car_Count] = count(Model), Model
from Car
group by Model
--6c.
select Customer.Customer_ID, [My Service Order Count] =
count(Service_Ticket_ID)
from Customer join Service_Ticket on Customer.Customer_ID =
Service_Ticket.Customer_ID
group by Customer.Customer_ID
having count(Customer.Customer_ID) > 1
-- 7a.
create login personnel
with password = 'personnel1to1'
create user personnel for login personnel
-- 7b.