Row numbers for a query in informix

后端 未结 6 2060
無奈伤痛
無奈伤痛 2020-12-19 11:15

I am using informix database, I want a query which you could also generate a row number along with the query

Like

select row_number(),firstName,lastN         


        
6条回答
  •  轮回少年
    2020-12-19 11:44

    Given a table called Table3 with 3 columns:

    colnum  name   datatype
    ======= =====  ===
    1       no     text;
    2       seq    number;
    3       nm     text;
    

    NOTE: seq is a field within the Table that has unique values in ascending order. The numbers do not have to be contiguous.

    Here is query to return a rownumber (RowNum) along with query result

    SELECT table3.no, table3.seq, Table3.nm,
          (SELECT COUNT(*) FROM Table3 AS Temp
             WHERE Temp.seq < Table3.seq) + 1 AS RowNum
        FROM Table3;
    

提交回复
热议问题