火鸟 SQL 分组依据
Firebird SQL group by
我想按列 factd_poste_fact
分组,但出现此错误:
SQL error code = -104.
Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause).
代码:
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
您需要在子查询的分组依据中包含 facture_detail.fact_n
SELECT 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
我想按列 factd_poste_fact
分组,但出现此错误:
SQL error code = -104.
Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause).
代码:
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
您需要在子查询的分组依据中包含 facture_detail.fact_n
SELECT 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