Here is my table emp :
+---------+------------------+
| emp | id | color |
+---------+------------------+
| hary | 123 | red |
+---------+------------------+
| lary | 125 | green |
+---------+------------------+
| gary | 038 | red |
+---------+------------------+
| Kris | 912 | blue |
+---------+------------------+
| hary | 123 | red |
+---------+------------------+
| Ronn | 334 | green |
+---------+------------------+
Now I want to find out the count of each colour i.e red,green and blue;
On this context I’m trying to write down the query in terms of where color like '%bl%',like '%ree%',like %ed%. and to want this result
+--------------------------+
| red | blue | green |
+--------------------------+
| 3 | 1 | 2 |
+--------------------------+
I have tried this thing:
select count(case when color='green' then 1 end) as Green,count(case when
color='blue' then 1 end) as Blue,count(case when color='Red' then 1 end) as Red from emp;
I don’t want to hardcode their name(as I’ll use it in my code jdbc).
I’ll appreciate any input’s regarding this questain.
with where clause