Reputation: 575
The result of a temp table in sql is like:
ServiceType
-----------
E
I
I
E
I
D
I
D
E
I want the count of above result something like this (where I-Imp,E-Exp,D-Dom):
Type Count
------------
Exp 3
Imp 4
Dom 2
Can anyone please suggest me the best way to achieve this? I am trying to do this by creating an other temp table.
Upvotes: 0
Views: 88
Reputation: 32602
You can try this:
SELECT CASE ServiceType
WHEN 'I' THEN 'Imp'
WHEN 'E' THEN 'Exp'
WHEN 'D' THEN 'Dom' END AS Type
, COUNT(ServiceType) AS `Count`
FROM MyTable GROUP BY ServiceType
Result:
| TYPE | COUNT |
----------------
| Dom | 2 |
| Exp | 3 |
| Imp | 4 |
Upvotes: 5
Reputation: 2135
try this..
select type, count(type) from table
group by type.
Upvotes: 1