SQL question!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepjoye
    New Member
    • Nov 2007
    • 1

    SQL question!!

    Hi -

    I want to get the db2 SQL output of a query, WHERE B>=90 and wherever it find the matching condition it should fetch preceding 3 rows.

    For Example -
    A B
    - -
    1 5
    0 6
    5 8
    1 10
    2 20
    3 30
    4 98
    5 50
    11 55
    6 60
    7 70
    8 90
    9100

    So the output should be based on above criteria -
    A B
    - -
    1 10
    2 20
    3 30
    4 98
    11 55
    6 60
    7 70
    8 90

    Any help will be appreciated.

    Thanks
    Sandip
  • nearestniladri
    New Member
    • Nov 2007
    • 5

    #2
    If you want to get the first 3 rows, then your SQL statement need to be like:

    select * from table_name where B<=90 fetch first 3 rows only.


    Actually the statement is for fetching first n rows is:

    select * from table_name fetch first n rows only.

    Comment

    Working...