我想按列factd_poste_fact
进行分组,但我收到此错误:
SQL错误代码= -104 选择列表中的表达式无效(不包含在聚合函数或GROUP BY子句中)。
代码:
select
f.fact_n,
poste_facture ,
sum_montant_ttc
from
factures f
left outer join
(select
facture_detail.fact_n,
(facture_detail.factd_poste_fact) as poste_facture,
sum(facture_detail.factd_montant_ttc) as sum_montant_ttc
from
facture_detail
group by
(fact_d.fact_n,facture_detail.factd_poste_fact)
group by
f.fact_n, poste_facture, sum_montant_ttc
答案 0 :(得分:1)
您需要在子查询
中的group by中包含facture_detail.fact_nSELECT f.fact_n, poste_facture, sum_montant_ttc
FROM factures f
LEFT OUTER JOIN (SELECT fact_n, (factd_poste_fact) AS poste_facture, SUM(factd_montant_ttc) AS sum_montant_ttc
FROM facture_detail
GROUP BY factd_poste_fact, fact_n
) fact_d ON (f.fact_n = fact_d.fact_n)
GROUP BY f.fact_n, poste_facture, sum_montant_ttc