IFNULL函数在MySQL查询中不起作用

时间:2015-02-17 06:27:45

标签: mysql ifnull

我想要Grand Total的运营商。但是IFNULL功能不起作用。

SELECT 
      IFNULL(op.operator_name, "Grand Total") AS operator, 
      SUM(re.amount) AS amount 
FROM mobile_db.recharge re 
INNER JOIN mobile_db.operator op 
ON re.operator_id = op.operator_id
GROUP BY operator WITH ROLLUP

1 个答案:

答案 0 :(得分:0)

您不能将ALIAS用作GROUP BY参数。请尝试我的查询:

SELECT 
     IFNULL(op.operator_name, "Grand Total") AS operator, 
     sum(re.amount) AS amount 
FROM mobile_db.recharge re 
INNER JOIN mobile_db.operator op ON re.operator_id = op.operator_id
GROUP BY IFNULL(op.operator_name, "Grand Total") WITH ROLLUP