Question

I have a query like this

 SELECT ROW_NUMBER() over (order by nomorMahasiswa) AS number
       ,namaMataKuliah
 FROM t_mahasiswa

and the output like this

NUMBER  LESSON
1   Algoritma dan Pemrograman
2   Pemrograman berorentiasi obyek
3   jaringan
4   Pemrograman Web
5   jaringan
6   jaringan
7   Algoritma dan Pemrograman
8   Algoritma dan Pemrograman
9   algoritma
10  oop
11  oop
12  algoritma
13  algoritma
14  algoritma

I want to make query like that in INFORMIX 11.50, What must I do ?

Was it helpful?

Solution

This syntax isn't available at version 11.50 either 11.70.
The feasible option here is create your own UDR (user defined routine = procedure) to simulate the situation.

Will be some limitations...
This is my version of row_number....

create procedure row_number(initial integer) returning integer as row_number;
define global i integer default 0;
  if initial = 0 then
    let i = 0;
    return 0 ;
  end if;
  let i = i+1;
   return i ;
end procedure
document "Simplified and similar function to row_number() from SqlServer.",
"Need to reset the counter before each sql statement with ",
"execute procedure row_number(0) OR declare into FROM clause",
"For use in SELECT statement use any other number in parameter:",
"select row_number(1) , tabname from systables;",
"OR select row_number(1) , tabname from systables, table(row_number(0))",
"By Cesar Inacio Martins - www.imartins.com.br"
with listing in "/tmp/row_number.out"
;
Routine created.
;

-- Here the syntax of call should always be the same, row_number(1) to
-- the field and table(row_number(0)) for table

select  first 5 row_number(1), tabname::char(20) 
from systables, table(row_number(0));

(expression) (expression)         
           1 systables           
           2 syscolumns          
           3 sysindices          
           4 systabauth          
           5 syscolauth          
5 row(s) retrieved.

select  first 5 row_number(1), tabname::char(20) 
from systables, table(row_number(0))
order by 1 desc;

(expression) (expression)         
         245  SMIVERSION         
         244 sysextspaces        
         243 syscompdicts        
         242 syscmsm             
         241 syssqexplain        
5 row(s) retrieved.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top