How to filter rows on a complex filter

Posted by dan on Stack Overflow See other posts from Stack Overflow or by dan
Published on 2010-06-09T20:01:32Z Indexed on 2010/06/09 20:12 UTC
Read the original article Hit count: 175

Filed under:
|
|

I have these rows in a table

ID  Name    Price   Delivery
==  ====    =====   ========
1   apple   1       1
2   apple   3       2
3   apple   6       3
4   apple   9       4
5   orange  4       6
6   orange  5       7

I want to have the price at the third delivery (Delivery=3) or the last price if there's no third delivery.

It would give me this :

ID  Name    Price   Delivery
==  ====    =====   ========
3   apple   6       3
6   orange  5       7

I don't necessary want a full solution but an idea of what to look for would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle