0

I want operator by Grand Total. but IFNULL function is not working.

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
Rigel1121
  • 2,022
  • 1
  • 17
  • 24
Shihab
  • 83
  • 1
  • 3
  • 10

1 Answers1

0

You cannot use ALIAS as GROUP BY parameter. Try my query below:

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
Rigel1121
  • 2,022
  • 1
  • 17
  • 24