Any Advice with Mysql Count

Go To StackoverFlow.com

2

i have a t_class table in mySql,
in this table there are 3 columns, No, CLASS and POINT.
and there are approximately 5000 records in this table. i want the count of classes in this table.

No    CLASS     POINT
1     9         100
2     10        70
3     11        80
4     9         90
5     10        50
6     M         60
7     M         70
8     9         40
9     10        90
10    11        90
11    M         80
12    M         75
13    11        40
14    10        100
15    9         60

As you see there 4 types of classes - 9, 10, 11 and M.
But there is one problem. When it calculates the count of classes it must summarize 11-th and M th classes. For example

CLASS    COUNT
9        4
10       4
11       7

Thanks.

2012-04-04 07:00
by namco


5

SELECT CLASS, COUNT(*) AS CNT
FROM table
GROUP BY CASE WHEN CLASS='M' THEN '11' ELSE CLASS END
2012-04-04 07:06
by cctan
Thanks cctan for answer.. - namco 2012-04-04 07:37
Ads