I have an SQL statement that looks like the following:
SELECT each_req.serial_num,
each_req.sponsors,
each_req.subscription_code,
format(sum(trans.trans_data-ifnull(trans.trans_prev,0))/3600,2) as hours,
each_req.subject
FROM each_req,
transactions AS trans
WHERE trans.serial_num = each_req.serial_num
AND trans.type != 'priority'
AND trans.actor LIKE 'username'
AND trans.trans_date > unix_timestamp('2015-07-29 00:00:00')
AND trans.trans_date < unix_timestamp('2015-07-29 14:22:03')
GROUP BY each_req.serial_num
The problem is that the trans.trans_prev
and trans.trans_data
has a mix of data types based on what kind of trans.trans_type
it is.
I have the line format(sum(trans.trans_data-ifnull(trans.trans_prev,0))/3600,2) as hours,
in my SQL statement. I essentially want this to equal 0
if trans.trans_type != 'time_worked'
.
I already have an ifnull
check in there, however I am unclear how I can add an if
statement that will compare against the columns data.
Aucun commentaire:
Enregistrer un commentaire