Correlated Subqueries 2

In the code given in the lesson

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

i am not able to understand two things:

  1. the logic behind ‘f.id< flights.id’
  2. the logic of ‘flights.carrier+1’
3 Likes

I’m having trouble with this one too.

nvm, I got it, I was off by one word!
SELECT origin, id,
(SELECT COUNT(*)
FROM flights f
WHERE f.id < flights.id
AND f.origin=flights.origin) + 1
AS flight_sequence_number
FROM flights;

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.