2016-08-16 18 views
0

我不是DB人,我無法理解爲什麼這個簡單的案例在5.6上完美工作,但在5.7奇怪的方式失敗。奇怪的組/在MySQL中的排序行爲5.7

使用案例:獲得收視率最高的喜劇列表中包含標題,作者的一些信息一起...

只要我只選擇非文本colunm,然後將其排序正確

  SELECT c.id, c.title IF(AVG(r.score) IS NOT NULL, AVG(r.score), 0) as `rateScore`, COUNT(r.`entityId`) as `rateCount` 
     FROM `manga_comic` as c 
     LEFT JOIN `base_rate` as r 
     ON(r.`entityType` = 'comic' AND c.id = r.`entityId`) 


     GROUP BY c.`id` 
     ORDER BY `rateScore` DESC, rateCount DESC 

添加「c.description」之類的文本列將忽略rateScore,而rate rateCount。

再一次,我只有5.7(或者可能是一些混亂的配置)。我希望不要因爲升級到MySQL而重新編碼很多屏幕5.7

+0

可能重複之前(HTTP://計算器。 com/questions/37089347/is-there-any-value-capability-for-mysql-5-6) – e4c5

+0

是否在select和group by中添加了text列? – xQbert

+0

@ e4c5:這是一些「嚴重」的快速回復,它看起來很有希望,謝謝 –

回答

0

我明白了。由於從Is there ANY_VALUE capability for mysql 5.6?

 SELECT DISTINCT c.id, 
    c.author, 
    c.title, 
    ....... , 

    r.avgScore as `rateScore`, r.`rateCount` , 

    f.id as mediaId , f.type as mediaType, f.data as cover 

       FROM `manga_comic` as c 
       LEFT JOIN (
       Select entityId, AVG(r0.score) as `avgScore`, COUNT(r0.`entityId`) as `rateCount` 
       FROM `base_rate` as r0 

       Where r0.`entityType` = 'comic' 
        GROUP BY r0.`entityType` , r0.`entityId` 
       ) r 
       ON( c.id = r.`entityId`) 



       LEFT JOIN entity e on (`c`.`id` = `e`.`entityId` and e.entityType='comic' and plugin='manga') 
       LEFT JOIN media_file f on (`e`.`id` = `f`.`entityId` and f.type='cover') 
       WHERE 1 


       ORDER BY `rateScore` DESC , rateCount DESC 
       LIMIT 0, 20 

答案的提示謝謝e4c5的鏈接和其他人的時間和支持。

結論:?有沒有\ _Value爲MySQL 5.6功能]到目前爲止,我有這麼多的麻煩從MySQL 5.7所以三思您PROD升級到5.7