これが私のテーブルemp
です:
+---------+------------------+
| emp | id | color |
+---------+------------------+
| hary | 123 | red |
+---------+------------------+
| lary | 125 | green |
+---------+------------------+
| gary | 038 | red |
+---------+------------------+
| Kris | 912 | blue |
+---------+------------------+
| hary | 123 | red |
+---------+------------------+
| Ronn | 334 | green |
+---------+------------------+
ここで、各色、つまり赤、緑、青の数を調べたいと思います。
where color like '%bl%',like '%ree%',like %ed%.
このコンテキストでは、この結果を求めてクエリを書き留めようとしています。
+--------------------------+
| red | blue | green |
+--------------------------+
| 3 | 1 | 2 |
+--------------------------+
私はこれを試しました:
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;
それらの名前をハードコーディングしたくありません(コードjdbcで使用するため)。この質問に関するご意見をいただければ幸いです。