How to design a query that gives count of different parameters based on different condition from a single table I have a table books containing columns as bookid, issue_date,return_date.

Once a book is issued from library an issue_date corresponding to it is made into the table while return_date can have valid date or null value.

Now the situation is I want the number of books for the following cases:

1. no. of books issued and returned on the same day as SAME_DAY
2. no. of books that have not been returned until now (i.e. return_date is null) as NOT_RET
3. no. of books that were issued and returned on separate days as SEP_DAY

I want all these numbers as output of a single query as for example : 

SAME_DAY    NOT_RET    SEP_DAY
______________________________
   12          13       10
select sum(case when issue_date = return_date then 1 else 0 end) SAME_DAY,
       sum(case when return_date is null then 1 else 0 end) NOT_RET,
       sum(case when issue_date &lt;&gt; return_date then 1 else 0 end) SEP_DAY
  from books;