Sainandoor,
I believe you are confusing the stored procedure CASE statement with the regular CASE control flow function. In the regular CASE function, you don't use the END CASE, whereas with the stored procedure CASE statement, you do. They serve different purposes. Here is what you would use:
mysql> SELECT * FROM numbers;
+-----------+
| my_number |
+-----------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
+-----------+
7 rows in set (0.00 sec)
mysql> SELECT SUM(CASE WHEN my_number < 5 THEN 1 ELSE 0 END) as lessthan5 FROM numbers;
+-----------+
| lessthan5 |
+-----------+
| 4 |
+-----------+
1 row in set (0.00 sec)
mysql> SELECT SUM(IF(my_number < 5, 1, 0)) as lessthan5 FROM numbers;
+-----------+
| lessthan5 |
+-----------+
| 4 |
+-----------+
1 row in set (0.02 sec)
As you can see, I've shown the use of the SUM(IF()) alternative that you might find slightly more efficient/easier.
Hope this helps,
Jay Pipes
Community Relations Manager, North America, MySQL Inc.
Got Cluster?
http://www.mysql.com/cluster
Personal:
http://jpipes.com