This is a definition for a field in a very nice view I've designed to solve a problem:
(SELECT INTERNETID
FROM (SELECT InternetId, row_number() OVER (ORDER BY InternetId) AS Fila
FROM PaydayLoans Loan
WHERE Loan.CUSTOMERID = cust.CUSTOMERID
GROUP BY InternetId) AS Temporal
WHERE Temporal.Fila = 3) = loan.InternetId THEN 1 ELSE 0 END) AS ThirdPayments
I'm sure Itzik Ben-Gan can find a better way to do this but I hope his book helps me 🙂
Cheers,
Mauricio