w3resource
SQL exercises

SQL exercises on hospital Database: Count the number of unavailable rooms for each block in each floor

SQL hospital Database: Exercise-25 with Solution

25. Write a query in SQL to count the number of unavailable rooms for each block in each floor.

Sample table: room


Sample Solution:

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

Sample Output:

 Floor | Block | Number of available rooms
-------+-------+---------------------------
     1 |     2 |                         1
     2 |     1 |                         1
     2 |     2 |                         1
     3 |     1 |                         1
     3 |     3 |                         1
     4 |     1 |                         1
     4 |     3 |                         1
(7 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 count the number of available rooms for each block in each floor.
Next: Write a query in SQL to find out the floor where the maximum no of rooms are available.

What is the difficulty level of this exercise?



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