我有一个如下所示的SQL语句:
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
问题在于trans.trans_prev
和trans.trans_data
根据trans.trans_type
的类型有多种数据类型。
我的SQL语句中有format(sum(trans.trans_data-ifnull(trans.trans_prev,0))/3600,2) as hours,
行。如果0
,我基本上希望它等于trans.trans_type != 'time_worked'
。
我已经在那里进行了ifnull
检查,但是我不清楚如何添加一个if
语句来与列数据进行比较。