I have a little problem with a piece of SQL code. I have a table Paiements_17_18 and I would like to create a single-line query that calculates:
- the total of the Amount field,
- the first date of Date_Regulation field,
- the last date of Date_Regulation field,
- the distinct values of N_Facture field.
All this from a sub request of the style SELECT TOP n FROM ....
I tried this:
SELECT Sum(P.Montant) AS TotalMontant,
First(P.Date_Regulation) AS PremièreDate,
Last(P.Date_Regulation) AS DernièreDate,
First(P.N_Facture) AS PremièreFacture,
Last(P.N_Facture) AS DernièreFacture,
(SELECT Count(N_Facture)
FROM (SELECT DISTINCT N_Facture FROM Paiements_17_18)) AS NombreFactures
FROM (SELECT TOP 5 Paiements_17_18.*
FROM Paiements_17_18
ORDER BY Paiements_17_18.ID_Paiement DESC) AS P;
But I get an error of "P"
(The Microsoft Access database engine cannot find the input table or query" P" . Make sure it exists and that its name is spelled correctly)
Can you help me please?
P.Pat end even though here it is posted. Very odd! I tested thatSELECT Count(...) FROM (SELECT DISTINCT ...)without an issue!