我想要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
答案 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