• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Display the sequence numbers on the output rows of a select in Oracle 10g

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an Employee table with a salary column. I want to find the distinct salaries in the Employee table.

SQL> select distinct salary from Employee order by salary;

It only display the distinct salaries:

1000
1100
12345
....

Now I want to put a line sequence number in front of each distinct salary. Something like:

1: 1000
2: 1100
3: 12345

How should I change the select query? I know rownum does not help here.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use "select rownum, distinct salary from emp order by salary"
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
 
Tejas Jain
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Goutham Pallipati wrote:use "select rownum, distinct salary from emp order by salary"



I got an ORA-00936 error: missing expression
 
Tejas Jain
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ireneusz Kordal wrote:Try this:



This works. Thanks.

Now what if I only want to find the 3rd highest salary?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Todd Jain wrote:

Goutham Pallipati wrote:use "select rownum, distinct salary from emp order by salary"



I go an ORA-00936 error: missing expression



You have got an error because this query has a syntax error
- DISTINCT can appear right after SELECT only ,and can applied to the whole row,
DISTINCT cannot be applied to individual columns.

The syntax of SELECT statement is:
reply
    Bookmark Topic Watch Topic
  • New Topic