How to do SQL select top N … in AS400

前端 未结 6 760
执笔经年
执笔经年 2020-12-28 13:40

How do you perform a

Select top N * from as400table

type query against an as400/db2 database

6条回答
  •  抹茶落季
    2020-12-28 14:22

    I am only a baby-geek when it comes to IBM--I am a SQL Server guy. But I found the rownumber approach (which I have used successfully in Oracle) did not work in DB2. I used this one:

    SELECT
         MYFIELD 
    FROM
         "SCHEMANAME"."TABLENAME" 
    WHERE
         FILTERCOL1 = 000001 
         AND FILTERCOL2 = 1 
    ORDER BY
         MYFIELD DESC FETCH FIRST ROW ONLY
    

    (I ordered descending because I needed the last value.)

    Hope this helps. Joey

提交回复
热议问题