Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/* NO 1 */
SELECT MAX(Quantity) as "MaxQuantity", MIN(Quantity) as
"MinQuantity",trunc(AVG(Quantity),2) as "AvgQuantity"
FROM TransactionDetail;
/* NO 2 */
SELECT MedicineTypeID, MedicineTypeName,
COUNT(MedicineID) as "MedicineCount"
FROM MsMedicine NATURAL JOIN MsMedicineType
GROUP BY MedicineTypeID, MedicineTypeName
ORDER BY 1;
/* NO 3 */
SELECT DoctorID, DoctorName, COUNT(DoctorID) as "TransactionCount"
FROM TransactionHeader NATURAL JOIN MsDoctor
WHERE EXTRACT(month from TransactionDate) < 7
GROUP BY DoctorID,DoctorName
ORDER BY 1;
/* NO 4 */
SELECT m.PatientID, m.PatientName, SUM(Quantity) as "TotalMedicineBough"
FROM TransactionDetail td JOIN TransactionHeader th
ON( th.TransactionID = td.TransactionID)
JOIN MsPatient m
ON(th.PatientID = m.PatientID)
WHERE td.MedicineID = 'ME008' AND Length(PatientName) > 7
GROUP BY m.PatientID, m.PatientName
ORDER BY 1;
Reynaldi – 000000 25047
/* NO 5 */
SELECT TO_CHAR(TransactionDate, 'YYYY') as "Year", MAX(Quantity)
FROM TransactionDetail NATURAL JOIN TransactionHeader
WHERE DoctorID = 'DC001'
GROUP BY TO_CHAR(TransactionDate, 'YYYY')
ORDER BY 1;
/* NO 6 */
SELECT PatientID, PatientName, COUNT(PatientID) as "TransactionCount"
FROM TransactionHeader NATURAL JOIN MsPatient
WHERE PatientPhone NOT LIKE '021%' AND PatientAddress NOT LIKE '% % %'
GROUP BY PatientID, PatientName
ORDER BY 1;
/* NO 7 */
SELECT md.DoctorID, md.DoctorName, TO_CHAR(md.DoctorBirthDate, 'dd Mon YYYY') as
"DoctorBirthday", SUM(td.Quantity) as "TotalMedicineSold"
FROM TransactionDetail td
JOIN TransactionHeader th
ON(th.TransactionID = td.TransactionID)
JOIN MsDoctor md
ON(th.DoctorID = md.DoctorID)
WHERE LENGTH(md.DoctorName) > 14
GROUP BY md.DoctorID, md.DoctorName, TO_CHAR(md.DoctorBirthDate, 'dd Mon YYYY');
Reynaldi – 000000 25047
/* NO 8 */
SELECT m.MedicineID, m.MedicineName, td.Quantity * m.MedicinePrice as "TotalProfit"
FROM MsMedicine m
JOIN TransactionDetail td
ON(td.MedicineID = m.MedicineID)
JOIN TransactionHeader th
ON(td.TransactionID = th.TransactionID)
WHERE TO_CHAR(th.TransactionDate, 'dd') BETWEEN 10 AND 20
GROUP BY m.MedicineID, m.MedicineName,td.Quantity * m.MedicinePrice;
/* NO 9 */
SELECT RPAD(th.TransactionID,5,' ') as "TransactionID", SUM(td.Quantity) as "TotalMedicine"
FROM TransactionDetail td
JOIN TransactionHeader th
ON(th.TransactionID = td.TransactionID)
WHERE TO_CHAR(th.TransactionDate, 'YYYY') = 2012
GROUP BY th.TransactionID
ORDER BY 1;
Reynaldi – 000000 25047
/* NO 10 */
-Tipe 1-
SELECT th.TransactionID, md.DoctorID, mp.PatientID, COUNT(td.MedicineID)
FROM TransactionDetail td
JOIN TransactionHeader th
ON(th.TransactionID = td.TransactionID)
JOIN MsDoctor md
ON(th.DoctorID = md.DoctorID)
JOIN MsPatient mp
ON(th.PatientID = mp.PatientID)
WHERE TO_NUMBER(TRIM('A' FROM TRIM('P' FROM mp.PatientID))) > 4
AND MOD(TO_NUMBER(TRIM('A' FROM TRIM('P' FROM mp.PatientID))),4) = 0
GROUP BY th.TransactionID, md.DoctorID, mp.PatientID
ORDER BY 2;
-Tipe 2-
SELECT th.TransactionID, md.DoctorID, mp.PatientID, COUNT(td.MedicineID)
FROM TransactionDetail td
JOIN TransactionHeader th
ON(th.TransactionID = td.TransactionID)
JOIN MsDoctor md
ON(th.DoctorID = md.DoctorID)
JOIN MsPatient mp
ON(th.PatientID = mp.PatientID)
WHERE
MOD(TO_NUMBER(TRIM('A' FROM TRIM('P' FROM mp.PatientID))),4) = 0
GROUP BY th.TransactionID, md.DoctorID, mp.PatientID
ORDER BY 2;
Reynaldi – 000000 25047
/* NO 11 */
SELECT m.MedicineID, m.MedicineName
FROM MsMedicine m
JOIN MsMedicineType mt
ON(m.MedicineTypeID = mt.MedicineTypeID)
WHERE mt.MedicineTypeName = 'Balm'
GROUP BY m.MedicineID, m.MedicineName
ORDER BY 1;
/* NO 12 */
SELECT md.DoctorID, md.DoctorName, md.DoctorPhone,
TO_CHAR(md.DoctorBirthDate, 'YYYY') DoctorBirthYear
FROM MsDoctor md, TransactionHeader th
GROUP BY md.DoctorID, md.DoctorName, md.DoctorPhone,
TO_CHAR(md.DoctorBirthDate, 'YYYY')
MINUS
SELECT md.DoctorID, md.DoctorName, md.DoctorPhone,
TO_CHAR(md.DoctorBirthDate, 'YYYY') DoctorBirthYear
FROM MsDoctor md, TransactionHeader th
WHERE md.DoctorID = th.DoctorID
GROUP BY md.DoctorID, md.DoctorName, md.DoctorPhone,
TO_CHAR(md.DoctorBirthDate, 'YYYY');
FROM TransactionHeader th
JOIN MsDoctor md
ON(th.DoctorID = md.DoctorID));*/
/* NO 13 */
SELECT m.MedicineName, mt.MedicineTypeName, m.MedicinePrice FROM
MsMedicine m
JOIN MsMedicineType mt
ON mt.MedicineTypeID = m.MedicineTypeID
JOIN TransactionDetail d
ON d.MedicineID = m.MedicineID
JOIN TransactionHeader h
ON d.TransactionID = h.TransactionID
WHERE EXTRACT(Month from h.TransactionDate) = 12
ORDER BY m.MedicinePrice DESC;
/* NO 14 */
SELECT mm.MedicineID, mm.MedicineName,
'Rp. '|| mm.MedicinePrice as "MedicinePrice"
FROM MsMedicine mm
JOIN TransactionDetail td
ON mm.MedicineID = td.MedicineID
JOIN TransactionHeader th
ON td.TransactionID = th.TransactionID
JOIN MsDoctor md
ON th.DoctorID = md.DoctorID
WHERE th.DoctorID NOT LIKE 'DC001'
GROUP BY mm.MedicineID, mm.MedicineName, mm.MedicinePrice
ORDER BY 1;
Reynaldi – 000000 25047
/* NO 15 */
SELECT DISTINCT p.PatientID, p.PatientName,
TO_CHAR(p.PatientBirthDate, 'yyyy') as "PatientBirthYear"
FROM MsPatient p
JOIN TransactionHeader th
ON(th.PatientID = p.PatientID)
JOIN MsDoctor d
ON(th.DoctorID = d.DoctorID)
WHERE TO_CHAR(p.PatientBirthDate, 'yyyy-mm-dd') > TO_CHAR(d.DoctorBirthDate, 'yyyy-mm-
dd')
ORDER BY 1;
/* NO 16 */
SELECT h.transactionID, TO_CHAR(h.TransactionDate,'yyyy.mm.dd')
as "TransactionDate"
FROM transactionHeader h
JOIN transactionDetail d
ON (h.TransactionID = d.TransactionID)
JOIN MsMedicine m
ON m.MedicineID = d.MedicineID
JOIN MsMedicineType mt
ON (m.MedicineTypeID = mt.MedicineTypeID)
WHERE mt.MedicineTypeName <> 'Syrup' and m.MedicinePrice > 15000
GROUP BY h.TransactionID, h.TransactionDate
ORDER BY 1;
/* NO 17 */
SELECT PatientID, PatientName, REPLACE(PatientAddress,'Street',' ')PatientRoadAddress
FROM MsPatient
WHERE LENGTH(PatientName) > LENGTH(REPLACE(PatientAddress,'Street',' '));
Reynaldi – 000000 25047
/* NO 18 */
SELECT p.PatientName, TO_CHAR(p.PatientBirthDate, 'dd/mm/yy') as "PatientBirthDate",
p.PatientAddress
FROM MsPatient p
JOIN TransactionHeader h
ON(p.PatientID = h.PatientID)
JOIN MsDoctor d
ON(d.DoctorID = h.DoctorID)
WHERE TO_CHAR(h.TransactionDate, 'dd') BETWEEN 15 AND 25
AND d.DoctorName LIKE '%j%'
OR d.DoctorName LIKE '%k%';
/* NO 19 */
SELECT p.PatientID, p.PatientName,
SUBSTR(UPPER(p.PatientName),1,2) as "INITIAL",
p.PatientBirthDate, COUNT(*)|| ' Transaction(s)'
FROM MsPatient p
JOIN TransactionHeader h
ON(h.PatientID = p.PatientID)
WHERE p.PatientID = h.PatientID
GROUP BY p.PatientID, p.PatientName,
SUBSTR(UPPER(p.PatientName),1,2), p.PatientBirthDate
ORDER BY p.PatientID;
/* NO 20 */
SELECT DoctorID, DoctorName, TO_CHAR(DoctorBirthDate, 'Mon dd yyyy') as
"DoctorBirthDate"
FROM MsDoctor
WHERE TO_CHAR(DoctorBirthDate, 'yyyy') = '1994'
OR TO_CHAR(DoctorBirthDate, 'yyyy') = '1954';
Reynaldi – 000000 25047
SCREENSHOTS
NO 1
NO 2
NO 3
Reynaldi – 000000 25047
NO 4
NO 5
NO 6
Reynaldi – 000000 25047
NO 7
NO 8
NO 9
Reynaldi – 000000 25047
NO 10_1
NO 10_2
NO 11
Reynaldi – 000000 25047
NO 12
NO 13
Reynaldi – 000000 25047
NO 14
NO 15
Reynaldi – 000000 25047
NO 16
NO 17
Reynaldi – 000000 25047
NO 18
NO 19
NO 20