4
4
Orthopedics 3
2
15
5
5
Dermatology 4
1
15
6
6
Radiology
2
2
6
7
7
Oncology 1
3
8
8
8
Emergenc... 6
5
10
9
9
Psychiatry 0
1
6
10 10
General S... 10
6
12
Question 8:
Picture 7.1
Create a function named F1 which calculates and returns an integer number which is the number of distinct patients having appointments with doctors of a given department, where departmentID int is the input parameter of the function.
For example, when we call the F1 function in the following query for calculating the number of distinct patients having appointments with the two departments 'Cardiology' and 'Pediatrics', the results must be shown as in the following figure:
select DepartmentID, Name, dbo. F1 (DepartmentID) as NumberOfPatients
from Departments
where Departments. Name in ('Cardiology', 'Pediatrics')
DepartmentID
Name
NumberOfPatients
1
1
Cardiology
37
2
3
Pediatrics
32
Zoom
+ 100%
Close