• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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:
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic