Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL error : sql_mode=only_full_group_by

Tags:

mysql

i have this script where i'm used to do a simple projection for a dynamic result

    SELECT 
    M.nom_utilisateur, 
    SUM(M.montant_bulletin ) as Montant_Total_BS,
    SUM(M.montant_payer   ) as Montant_Total_payer,
    COUNT(M.ref_bs ) as nbr_bs_total,

(SELECT COUNT(*) FROM mutuelle_bi.`Mutuelle` WHERE nom_utilisateur = M.nom_utilisateur  AND (M.nom_assurence  = "Star" AND M.etat_bs = "Remboursé")) as nbr_bs_total_payer,

(SELECT COUNT(*) FROM mutuelle_bi.`Mutuelle` WHERE nom_utilisateur = M.nom_utilisateur  AND (M.nom_assurence  = "Star" AND M.etat_bs = "Non remboursé")) as nbr_bs_non_payer,

(SELECT COUNT(*) FROM mutuelle_bi.`Mutuelle` WHERE nom_utilisateur = M.nom_utilisateur  AND (M.nom_assurence  = "Star" AND M.etat_bs = "En cours")) as nbr_bs_en_cours,

(SELECT COUNT(*) FROM mutuelle_bi.`Mutuelle` WHERE nom_utilisateur = M.nom_utilisateur  AND (M.nom_assurence  = "Star" AND M.etat_bs = "Nouveau")) as nbr_bs_nouveau
    FROM mutuelle_bi.`Mutuelle` M
    WHERE M.nom_assurence  = "Star"
    GROUP BY M.nom_utilisateur

but something goes wrong ; as i have this error :

1055 - Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mutuelle_bi.M.etat_bs' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

enter image description here

How may i modify my script by the way to solve this problem , given that i shouldn't modify any config file of my sql server . and i should only write scripts

Any Suggestions ??

like image 795
firasKoubaa Avatar asked Dec 15 '16 12:12

firasKoubaa


1 Answers

You can also try to disable the only_full_group_by setting:

set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Worked for me.

like image 137
Victor Gazotti Avatar answered Sep 20 '22 16:09

Victor Gazotti