52 lines
1.3 KiB
Markdown
52 lines
1.3 KiB
Markdown
3. 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.
|
|
|
|
```SQL
|
|
SELECT patient_name
|
|
FROM patient
|
|
WHERE age >= 50
|
|
ORDER BY patient_name;
|
|
```
|
|
|
|

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

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

|
|
|
|
6. Output the age of the oldest person who has donated in a hospital in Manchester.
|
|
|
|
```SQL
|
|
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%'
|
|
)
|
|
)
|
|
);
|
|
``` |