Search code examples
javasqloracle-databasejooqrownum

Selecting rownum/max(rownum) with jOOQ


I'm looking at a SQL query that uses Oracle's rownum pseudocolumn to select the row number as a fraction of the total rows:

ROWNUM/(MAX(ROWNUM) OVER())

I'm trying to accomplish the same thing with a query written via jOOQ. Is that possible?


Solution

  • While Dmitry's CUME_DIST() solution is probably better suited for the actual query, here's the ROWNUM solution in jOOQ, for the record:

    // Qualified
    DSL.rownum().div(DSL.max(DSL.rownum()).over());
    
    // With static imports of DSL.*
    rownum().div(max(rownum()).over());
    

    See also: DSL.rownum()