How to do SQL select top N … in AS400

前端 未结 6 762
执笔经年
执笔经年 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:21

    It's an old thread, thought I would contribute

    Consider using RANK() OVER() for the top n balances?

    WITH RANK_TBL AS
            (SELECT FIELD1 AS "ENDING BALANCE",
             RANK() OVER(ORDER BY FIELD1 DESC) AS "RANK NUMBER"
             FROM LIBRARY/TABLE)
    SELECT *
    FROM RANK_TBL
    WHERE "RANK NUMBER" < 6 
    

提交回复
热议问题