我有这个脚本,我习惯于为动态结果做一个简单的投影
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
但出了点问题;因为我有这个错误:
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
我如何通过解决此问题的方式修改我的脚本,
鉴于我不应该修改我的sql服务器的任何配置文件.我应该只编写脚本
有什么建议 ??
最佳答案
我想你只想要条件聚合:
原文链接:https://www.f2er.com/mysql/433727.htmlSELECT M.nom_utilisateur,SUM(M.montant_payer) as Montant_Total_payer,SUM(M.etat_bs = 'Remboursé') as nbr_bs_total_payer,SUM(M.etat_bs = 'Non remboursé') as nbr_bs_non_payer,SUM(M.etat_bs = 'En cours') as nbr_bs_en_cours,SUM(M.etat_bs = 'Nouveau') as nbr_bs_nouveau
FROM mutuelle_bi.`Mutuelle` M
WHERE M.nom_assurence = 'Star'
GROUP BY M.nom_utilisateur;