SQL - group by two bits

I have a SQL table with one bit column. If only one bit value is encountered in the rows of the table (in my case 1), how can I make a SELECT statement that shows, for example, the presence of both bit values ​​in the table, even if the other does not happen? This is the result I am trying to achieve:

+----------+--------+
| IsItTrue | AMOUNT |
+----------+--------+
|     1    |   12   |
|     0    |  NULL  |
+----------+--------+

      

I have already tried Google's answer, but with no success as English is not my native language and I am not familiar with SQL jargon.

+3


source to share


1 answer


select IsItTrue, count(id) as Amount from 
(select IsItTrue, id from table
union
select 1 as IsItTrue, null as id
union
select 0 as IsItTrue, null as id) t
group by bool

      



+3


source







All Articles