私は3つのテーブルを持っています:
表Invoices (Invoice、InvoiceAmount(float)、その他の情報 ...)、表Payments (Payment、PaymentAmount(float)、その他の情報 ...)、表PaymentsDet (Id、Invoice、Payment、Amount(float))。表 PaymentsDet は、請求書と支払いを金額 (その支払いによって支払われた請求書の一部) に関連付けます。
各請求書に関する情報を返すクエリが必要+
IF (その請求書の支払いは 1 回のみ)
Payment,SUM(PayementsDet.Amount) , その他の支払い情報 ...
ELSE (複数回の支払いまたは支払いなし)
Count(Payment)、SUM(PayementsDet.Amount)、その他の支払い情報をNULL値または''で入力します。
お時間をいただきありがとうございます。これについて私を助けてくれる賢い人がいることを願っています。
編集 :
SELECT Factures.Facture, Factures.Client, Factures.DateFacture, Factures.MoisFacture, Factures.DateRéception, Factures.Echéance, Factures.Montant, Factures.TxTVA,
Factures.Activité,
(SELECT CASE WHEN SUM(Montant) IS NULL THEN '0' ELSE SUM(Montant) END AS Expr1
FROM RèglementsDet
WHERE (Facture = Factures.Facture) AND (Validé = 1)) AS MontantRegl,
(SELECT CASE WHEN COUNT(DISTINCT Règlements.Règlement) > '1' THEN COUNT(DISTINCT Règlements.Règlement)
WHEN COUNT(DISTINCT Règlements.Règlement) = '1' THEN
(SELECT MIN(Règlements.Règlement) AS Expr1
FROM Règlements INNER JOIN
RèglementsDet ON Règlements.Règlement = RèglementsDet.Règlement
WHERE (RèglementsDet.Facture = Factures.Facture)) END AS Règlement
FROM Règlements INNER JOIN
RèglementsDet AS RèglementsDet_2 ON Règlements.Règlement = RèglementsDet_2.Règlement
WHERE (RèglementsDet_2.Facture = Factures.Facture) AND (RèglementsDet_2.Validé = 1)) AS Règlement
FROM Factures LEFT OUTER JOIN
RèglementsDet AS RèglementsDet_1 ON Factures.Facture = RèglementsDet_1.Facture
GROUP BY Factures.Facture, Factures.Client, Factures.DateFacture, Factures.MoisFacture, Factures.DateRéception, Factures.Echéance, Factures.Montant, Factures.TxTVA,
Factures.Activité
誰かがより良い(より読みやすい)クエリを取得した場合、私はそれを理解したと思います。