Correlated Subqueries II Logic


#1

Hello,

I am not getting the logic behind the sequence requested in the following:

SELECT carrier, id,
(SELECT COUNT(*)
FROM flights AS f
WHERE f.id < flights.id
AND f.carrier=flights.carrier) + 1
AS flight_sequence_number
FROM flights;

Can someone translates to me what does f.id < flights.id mean? and also f.carrier-flights.carrier

I do know what the result should be but I want to understand the logic if it was put in a sentance rather than a code, what would be?

(I think It could be something like: the id of the assigned f is less than the flights id, and the carrier of the assigned f = flights carrier)

Thanks


#2

Hello,

I made a guide for getting through this exercise here, which goes through a lot of the logic:

but in essence, after going through those exercises the f.id < flights.id is essentially telling it to order the resulting table from the renamed table (flights AS f) in ascending order, it isn't actually about the logic of x < y.


#3