SQL Q4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Question 1

a: CREATE TABLE DELIVERY (


pakageID TEXT NOT NULL PRIMARY KEY,
dateDelivery DATE/TIME,
riderID TEXT NOT NULL,
icNum TEXT NOT NULL,
status TEXT,
PRIMARY KEY (pakageID),
FOREIGN KEY (icNum) references CUSTOMER,
FOREIGN KEY (riderID) references RIDER,
);
b:
SELECT COUNT (DISTINCT C.icNum) AS total_successful_pakages
FROM CUSTOMER C
JOIN DELIVERY D ON C.icNum = D.icNum
JOIN RIDER R ON D.riderID = R.riderID
WHERE D.status = ‘delivered’
AND MONTH(dateDelivered

c) SELECT COUNT(PAKAGEID), RIDERID


FROM DELIVERY
WHERE
STATUS = ‘UNSUCCESSFUL’
GROUP BY riderID;

d) SELECT R.riderName
FROM DELIVERY AS D, RIDER AS R
WHERE
D.rIderID =R.riderID
AND
D.status= ‘delivered’
ORDER BY R.riderName ASC;
*if

e)
SELECT D.pakageID AS “Pakage ID”, C.coutomerName AS “Customer Name”,D.status AS “Status”
FROM DELIVERY AS D, CUSTOMER AS C
WHERE
D.icNum =C. icNum
AND
D.status= ‘dilivered’;
*if strictly following the exact how the table and its data are represented

SELECT D.pakageID AS “Pakage ID”, C.coutomerName AS “Customer Name”,D.status AS “Status”


FROM DELIVERY AS D, CUSTOMER AS C
WHERE
D.icNum =C. icNum
ORDER BY D.pakageID ASC;
*if we want to display data in the DELIVERY table

You might also like