民众
当我运行以下查询时,我得到了无效使用按功能分组的错误
SELECT `Margin`.`destination`,
ROUND(sum(duration),2) as total_duration,
sum(calls) as total_calls
FROM `ilax`.`margins` AS `Margin`
WHERE `date1` = '2013-08-30' and `destination` like "af%"
AND ROUND(sum(duration),2) like "3%"
group by `destination`
ORDER BY duration Asc LIMIT 0, 20;
让我知道围绕
的工作答案 0 :(得分:2)
{<1}}子句在分组发生之前评估,因此WHERE
不能在其中使用;请改用SUM()
子句,分组后
HAVING
另请注意,实际上应该对数值使用数字比较运算,而不是字符串模式匹配。例如:
SELECT destination,
ROUND(SUM(duration), 2) AS total_duration,
SUM(calls) AS total_calls
FROM ilax.margins
WHERE date1 = '2013-08-30'
AND destination LIKE 'af%'
GROUP BY destination
HAVING total_duration LIKE '3%'
ORDER BY total_duration ASC
LIMIT 0, 20