w3resource
SQL exercises

SQL exercises on hospital Database: Count the number of available rooms in each block

SQL hospital Database: Exercise-22 with Solution

22. Write a query in SQL to count the number of available rooms in each block.

Sample table: room


Sample Solution:

SELECT blockcode AS "Block",
       count(*) "Number of available rooms"
FROM room
WHERE unavailable='false'
GROUP BY blockcode
ORDER BY blockcode;

Sample Output:

 Block | Number of available rooms
-------+---------------------------
     1 |                         9
     2 |                        10
     3 |                        10
(3 rows)

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 find the name and medication for those patients who did not take any appointment.
Next: Write a query in SQL to count the number of available rooms in each floor.

What is the difficulty level of this exercise?



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