MySQL: SELECT an extra column categorizing another column based on IF statements -
suppose command: select sessionid, sessionlength mytable;
generates table:
+-----------+---------------+ | sessionid | sessionlength | +-----------+---------------+ | 1 | 00:20:31 | | 2 | 00:19:54 | | 3 | 00:04:01 | ... | 7979 | 00:00:15 | | 7980 | 00:00:00 | | 7981 | 00:00:00 | +-----------+---------------+ 7981 rows in set (0.92 sec) but want generate table this:
+-----------+---------------+--------+ | sessionid | sessionlength | size | +-----------+---------------+--------+ | 1 | 00:20:31 | big | | 2 | 00:19:54 | big | | 3 | 00:04:01 | medium | ... | 7979 | 00:00:15 | small | | 7980 | 00:00:00 | small | | 7981 | 00:00:00 | small | +-----------+---------------+--------+ 7981 rows in set (0.92 sec) - something
bigwhen it'ssessionlength > 10 - something
mediumwhen it'ssessionlength <= 10 , sessionlength >=1 - something
smallwhne it'ssessionlength > 1
conceptually want this:
select sessionid, sessionlength, (sessionlength > 10 ? "big" : (sessionlength < 1 : "small" : "medium")) mytable; is there easy way this?
select sessionid, sessionlength, if( sessionlength > 10, "big", if( sessionlength < 1, "small", "medium")) size mytable; hth
Comments
Post a Comment