"Christopher Vaughan" <[EMAIL PROTECTED]> wrote on 30/03/2005 16:48:47:

> I have data in a table listed as 
> 44:22:22
> 333:33:33
> It stands for hhh:mm:ss
> I want to break each part of the data into different parts based on 
> the ':' to separate them.  Then I want to take that data and sum it.
> I wrote an if statement to parse through this table but I can't get 
> it to work.  I am not sure If my syntax is
> wrong because I can't find anything to check against it. 
> 
> Here is the syntax:
> 
> IF 
> (SELECT job_walltime
> FROM time
> WHERE CHAR_LENGTH( job_walltime ) >=9)
> THEN
> (SELECT sum( left( job_walltime,  '3'  )  ) hours, sum(mid( 
> `job_walltime` , 4, 2  )) , sum( right( job_walltime,  '2'  )  ) seconds
> FROM  `time`)
> ELSE
> (SELECT sum( left( job_walltime,  '3'  )  ) hours, sum(mid( 
> `job_walltime` , 3, 2  ) ), sum( right( job_walltime,  '2'  )  ) seconds
> FROM  `time`)
> END 
> 
> I know this isn't the only way to do this but this but this is the 
> first suggestion that comes to mind.  Any input would be great.

IF is an operator, not a command, so it comes after the SELECT. In C 
terms, it is more like the "?:" operator than an "if()...else". Thus you 
can do
 SELECT x, IF (x > y, "IS BIGGER THAN", "IS  SMALLER THAN"), y FROM table.



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to