You are on page 1of 4

JASON FERNANDO / 2301875963

-- no.1

SELECT MAX(Price) AS [Maximum Price], MIN(Price) AS [Minimum Price], [Average Price] =


CAST(ROUND(AVG(Price), 0) AS NUMERIC(10,2))
FROM MsTreatment

-- no.2

SELECT StaffPosition, Gender = LEFT(StaffGender, 1), [Average Salary] = 'Rp. ' +


CAST(CAST(AVG(StaffSalary) AS NUMERIC(10,2)) AS VARCHAR)
FROM MsStaff
GROUP BY StaffPosition, StaffGender

-- no.3

SELECT CONVERT(varchar, TransactionDate, 107) AS [TransactionDate], COUNT(TransactionID)


AS [Total Transaction per Day]
FROM HeaderSalonServices
GROUP BY TransactionDate

-- no.4

SELECT CustomerGender = UPPER(CustomerGender), [Total Transaction] =


COUNT(hss.CustomerID)
FROM HeaderSalonServices hss
INNER JOIN MsCustomer ON hss.CustomerId = MsCustomer.CustomerId
GROUP BY CustomerGender
JASON FERNANDO / 2301875963

-- no.5

SELECT TreatmentTypeName, COUNT(dss.TreatmentID) AS [Total Transaction]


FROM MsTreatmentType mtt, DetailSalonServices dss, MsTreatment mt
WHERE mtt.TreatmentTypeId = mt.TreatmentTypeId AND dss.TreatmentID = mt.TreatmentID
GROUP BY TreatmentTypeName
ORDER BY COUNT(dss.TreatmentID) DESC

-- no. 6

SELECT CONVERT(VARCHAR, TransactionDate, 106) AS [Date], SUM(Price) AS [Revenue per Day]


FROM HeaderSalonServices hss, MsTreatment mt, DetailSalonServices dss
WHERE hss.TransactionId = dss.TransactionId AND mt.TreatmentId = dss.TreatmentId
GROUP BY TransactionDate
HAVING SUM(Price) BETWEEN 1000000 AND 5000000

-- no. 7

SELECT REPLACE (mtt.TreatmentTypeId, 'TT0', 'Treatment Type') AS ID,


mtt.TreatmentTypeName,[Total Treatment per Type] = CAST(COUNT(dss.TreatmentId) AS
VARCHAR) + ' Treatment'
FROM MsTreatmentType mtt, DetailSalonServices dss, MsTreatment mt
WHERE mt.TreatmentId = dss.TreatmentId AND mt.TreatmentTypeId = mtt.TreatmentTypeId
GROUP BY mtt.TreatmentTypeId, mtt.TreatmentTypeName
HAVING COUNT(dss.TreatmentId) > 5

-- no. 8

SELECT LEFT(StaffName, CHARINDEX(' ', StaffName)-1) AS [StaffName], hss.TransactionID,


COUNT(dss.TransactionId) AS [Total Treatment per Transaction]
FROM MsStaff ms, HeaderSalonServices hss, DetailSalonServices dss
WHERE ms.StaffId = hss.StaffId AND hss.TransactionId = dss.TransactionId
GROUP BY StaffName, hss.TransactionId
JASON FERNANDO / 2301875963

-- no. 9

SELECT TransactionDate, CustomerName, TreatmentName, Price


FROM HeaderSalonServices hss, MsCustomer mc, DetailSalonServices dss, MsTreatment mt,
MsStaff ms
WHERE mc.CustomerId = hss.CustomerId AND hss.TransactionId = dss.TransactionId AND
dss.TreatmentId = mt.TreatmentId AND hss.StaffId = ms.StaffId
AND StaffName LIKE '%Ryan%' AND DATENAME(WEEKDAY, TransactionDate) = 'Thursday'
ORDER BY CustomerName ASC, TransactionDate ASC

-- no. 10

SELECT TransactionDate, CustomerName, SUM(Price) AS TotalPrice


FROM HeaderSalonServices hss, MsCustomer mc, DetailSalonServices dss, MsTreatment mt
WHERE hss.TransactionId = dss.TransactionId AND hss.CustomerId = mc.CustomerId AND
dss.TreatmentId = mt.TreatmentId
GROUP BY TransactionDate, CustomerName
JASON FERNANDO / 2301875963

You might also like