w3resource
SQL exercises

SQL exercises on hospital Database: Count the number of patients who booked an appointment with at least one physician

SQL hospital Database: Exercise-4 with Solution

4. Write a query in SQL to count the number of patients who booked an appointment with at least one physician.

Sample table: appointment


Sample Solution:

SELECT count(DISTINCT patient) AS "No. of patients taken at least one appointment"
FROM appointment;

Sample Output:

 No. of patients taken at least one appointment
------------------------------------------------
                                              4
(1 row)

Practice Online


E R Diagram of Hospital Database:

E R Diagram: SQL Hospital Database.

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:Write a query in SQL to obtain the name of the physicians who are the head of the department.
Next:Write a query in SQL to find the floor and block where the room number 212 belongs to.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming