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 big when it's sessionlength > 10
  • something medium when it's sessionlength <= 10 , sessionlength >=1
  • something small whne it's sessionlength > 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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -