I have a parcel table with the following fields (among others): inscricao
(Customer Registration), nrparcela
(Portion Number), dt_vencimento
(Expiration Date) and vlrparcela
Plot).
If the client has 10 parcels, there will be 10 records in the table with the column nrparcela
numbered from 1 to 10, with their due dates and (variant) values for that client.
How to group these records by selecting the number of the first parcel (usually '1'), the number of the last parcel, the value of the first parcel and the value of the last parcel?
The value of each plot may vary, with cases where the value of each plot is different from the other values of that plot.
I just got this:
SELECT inscricao, MIN(nrparcela) AS primeira_parcela,
MAX(nrparcela) AS ultima_parcela
FROM parcelas
GROUP BY inscricao
ORDER BY inscricao