0
I have a table of plots with the following fields (among others): inscricao
(Customer Registration), nrparcela
(Plot number), dt_vencimento
(Due Date) and vlrparcela
(Value of the Plot).
If the customer has 10 installments, there will be 10 records in the table with the column nrparcela
numbered from 1 to 10, with respective due dates and (varied) values for that customer.
How to group these records by selecting the number of the first installment (usually '1'), the number of the last installment, the value of the first installment and the value of the last installment?
The value of each parcel may vary, there are cases where the value of each parcel is different from the other values of that parcel.
That’s all I got:
SELECT inscricao, MIN(nrparcela) AS primeira_parcela,
MAX(nrparcela) AS ultima_parcela
FROM parcelas
GROUP BY inscricao
ORDER BY inscricao