Correlated Subqueries 2


#1

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'


#2

I'm having trouble with this one too.


#3

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;


#4

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