Ошибка плагина MantisBT GaugeSupport #1111: Недопустимое использование функции группы


Я использую MantisBT 1.2.19 для проекта отслеживания ошибок http://mantisbt.org/download.php.

Кроме того, я использую плагин gaugeSupport для поддержки голосования пользователей за ошибки для ранжирования ошибок (https://github.com/EvilRenegade/Gauge-Support)

Плагин не подходит для моего проекта mantis:

В файле плагина issue_ranking.php, есть запрос MySQL:

$dbquery = "SELECT  
    max(sd.bugid) as bugid,  
    count(sd.rating) as no_of_ratings,  
    sum(sd.rating) as sum_of_ratings,  
    avg(sd.rating) as avg_rating,  
    max(sd.rating) as highest_rating,  
    min(sd.rating) as lowest_rating,  
    IFNULL(bm2_count,0) AS bm2_count,  
    IFNULL(bm2_sum,0) AS bm2_sum,  
    IFNULL(bm1_count,0) AS bm1_count,  
    IFNULL(bm1_sum,0) AS bm1_sum,  
    IFNULL(b2_count,0) AS b2_count,  
    IFNULL(b2_sum,0) AS b2_sum,  
    IFNULL(b1_count,0) AS b1_count,  
    IFNULL(b1_sum,0) AS b1_sum  
FROM {$plugin_table} sd  
INNER JOIN {$bug_table} b ON sd.bugid = b.id  
LEFT OUTER JOIN (SELECT bugid, count(rating) as bm2_count, sum(rating) as bm2_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = -2) bm2 ON sd.bugid = bm2.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as bm1_count, sum(rating) as bm1_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = -1) bm1 ON sd.bugid = bm1.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as b2_count, sum(rating) as b2_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 2) b2 ON sd.bugid = b2.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as b1_count, sum(rating) as b1_sum FROM {$plugin_table} GROUP BY bugid, rating HAVING rating = 1) b1 ON sd.bugid = b1.bugid  
{$where_clause}  
GROUP BY sd.bugid  
ORDER BY sum(sd.rating) {$order}  
LIMIT {$start}{$noOfBugs}"; 

Что приводит к ошибке:

Database query failed. Error received from database was #1054: Unknown column 'rating' in 'having clause' for the query:  SELECT  
max(sd.bugid) as bugid,  
count(sd.rating) as no_of_ratings,  
sum(sd.rating) as sum_of_ratings,  
avg(sd.rating) as avg_rating,  
max(sd.rating) as highest_rating,  
min(sd.rating) as lowest_rating,  
IFNULL(bm2_count,0) AS bm2_count,  
IFNULL(bm2_sum,0) AS bm2_sum,  
IFNULL(bm1_count,0) AS bm1_count,  
IFNULL(bm1_sum,0) AS bm1_sum,  
IFNULL(b2_count,0) AS b2_count,  
IFNULL(b2_sum,0) AS b2_sum,  
IFNULL(b1_count,0) AS b1_count,  
IFNULL(b1_sum,0) AS b1_sum  
FROM mantis_plugin_GaugeSupport_support_data_table sd  
INNER JOIN mantis_bug_table b ON sd.bugid = b.id  
LEFT OUTER JOIN (SELECT bugid, count(rating) as bm2_count, sum(rating) as bm2_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = -2) bm2 ON sd.bugid = bm2.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as bm1_count, sum(rating) as bm1_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = -1) bm1 ON sd.bugid = bm1.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as b2_count, sum(rating) as b2_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = 2) b2 ON sd.bugid = b2.bugid  
LEFT OUTER JOIN (SELECT bugid, count(rating) as b1_count, sum(rating) as b1_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = 1) b1 ON sd.bugid = b1.bugid  
WHERE b.project_id = 1 AND b.resolution NOT IN (20,40,50,70,90) AND b.status != 90  
GROUP BY sd.bugid  
ORDER BY sum(sd.rating) DESC  
LIMIT 0,10.  

Когда я добавляю столбец "рейтинг" в в запросе я все еще получаю ошибку неправильного использования функции GROUP BY:

Database query failed. Error received from database was #1111: Invalid use of group function for the query:  SELECT  
max(sd.bugid) as bugid,  
count(sd.rating) as no_of_ratings,  
sum(sd.rating) as sum_of_ratings,  
avg(sd.rating) as avg_rating,  
max(sd.rating) as highest_rating,  
min(sd.rating) as lowest_rating,  
IFNULL(bm2_count,0) AS bm2_count,  
IFNULL(bm2_sum,0) AS bm2_sum,  
IFNULL(bm1_count,0) AS bm1_count,  
IFNULL(bm1_sum,0) AS bm1_sum,  
IFNULL(b2_count,0) AS b2_count,  
IFNULL(b2_sum,0) AS b2_sum,  
IFNULL(b1_count,0) AS b1_count,  
IFNULL(b1_sum,0) AS b1_sum  
FROM mantis_plugin_GaugeSupport_support_data_table sd  
INNER JOIN mantis_bug_table b ON sd.bugid = b.id  
LEFT OUTER JOIN (SELECT bugid, rating, count(rating) as bm2_count, sum(rating) as bm2_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = -2) bm2 ON sd.bugid = bm2.bugid  
LEFT OUTER JOIN (SELECT bugid, rating, count(rating) as bm1_count, sum(rating) as bm1_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = -1) bm1 ON sd.bugid = bm1.bugid  
LEFT OUTER JOIN (SELECT bugid, rating, count(rating) as b2_count, sum(rating) as b2_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = 2) b2 ON sd.bugid = b2.bugid  
LEFT OUTER JOIN (SELECT bugid, rating, count(rating) as b1_count, sum(rating) as b1_sum FROM mantis_plugin_GaugeSupport_support_data_table GROUP BY bugid, rating HAVING rating = 1) b1 ON sd.bugid = b1.bugid  
WHERE b.project_id = 1 AND b.resolution NOT IN (20,40,50,70,90) AND b.status != 90  
GROUP BY sd.bugid  
ORDER BY sum(sd.rating) DESC  
LIMIT 0,10.  

Кто-нибудь знает, как правильно настроить плагин GaugeSupport для Mantis?

Спасибо!

Author: Jetic Cuntz, 2015-05-11

1 answers

Комментарии Абика Чакраборти решили проблему:

"Вы не можете использовать агрегатную функцию в предложении order by Просто используйте порядок по sum_of_ratings".

Спасибо!

 0
Author: Jetic Cuntz, 2016-06-08 15:06:42