The relation book (title,price) contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL query list?
from book as B
where (select count(*)
from book as T
where T.price>B.price) < 5
Titles of the four most expensive books
Title of the fifth most inexpensive book
Title of the fifth most expensive book
Titles of the five most expensive books
Here for T.A i.e.100 , it will get (50,20) from B.,count will be =2
Am I doing mistake?
but getting min 5 value :(
srestha pls check this
here for 600 in B count value will be 0 which is less than 5 we should include this ?
@ utkarsh , you are going in the opposite direction ,
first run the outer query .. in the outer query we select a tuple from B . Suppose we selected 100 from B.
now come inside the inner query .. it says ..
it means .. for that selected tuple of B , how many tuples in T are greater ..
thus it will return 4 for 100 and 0 for 600 .
its a really nice question :)
Thank you so much Arjun Sir!