MySQL如果单元格等于此,则使用数字,否则为零

时间:2015-07-29 14:37:46

标签: mysql if-statement

我有一个如下所示的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_prevtrans.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语句来与列数据进行比较。

0 个答案:

没有答案