1. Using IF
http://www.experts-exchange.com/Database/MySQL/Q_20522525.html
mysql> SELECT (if(answer=1,1,0))yes,
sum(if(answer='2','1','0')) no,
sum(if(answer=0,1,0))don_t_care
FROM favicon_poll;
+------+------+------------+
yes no don_t_care
+------+------+------------+
3 13 2
+------+------+------------+
1 row in set (0.00 sec)
2. Using CASE
Conversion of Oracle Decode to MySQL Case
http://www.ispirer.com/doc/sqlways38/Output/SQLWays-1-041.html
mysql> select CASE answer when 1 THEN 'yes' when 2 THEN 'no' else 'unknown' end from favicon_poll;
More information--------------------------------------------------------
mysql elt() and field() functions
http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_elts
Oracle Decode and CASE
MySQL equivalent to Oracle Decode
http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_elt
Expert Exchange Article
http://www.experts-exchange.com/Database/MySQL/Q_20522525.html
No comments:
Post a Comment