Files
G4G0-1/Semester 1/Database Systems/Assignment/Querying Database.md
2024-01-16 13:48:46 +00:00

1.3 KiB

  1. List the names of patients who are at least fifty years old. Your query should always generate a list in which the names are sorted in alphabetical order. The ordering must not depend upon the order in which you entered data into your database.
SELECT patient_name
FROM patient
WHERE age >= 50
ORDER BY patient_name;

  1. List the name of each type of organ, together with the total number of donations of that type of organ.
SELECT organ_type, COUNT( organ_type )
FROM organ
INNER JOIN operation ON operation.organ_id = organ.organ_id
GROUP BY organ_type;

  1. List the identifiers of hospitals where a transplant has been performed, together with the number of transplant operations at the hospital.
SELECT hospital_id, COUNT( hospital_id )
FROM transplant_unit
INNER JOIN operation ON transplant_unit.unit_id = operation.unit_id
GROUP BY hospital_id;

  1. Output the age of the oldest person who has donated in a hospital in Manchester.
SELECT age
FROM donor
WHERE donor_id IN (
	SELECT donor_id
	FROM operation
	WHERE unit_id IN (
		SELECT unit_id
		FROM transplant_unit
		WHERE hospital_id IN (
			SELECT hospital_id
			FROM hospital
			WHERE city LIKE '%Manchester%'
		)
	)
);