Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Avoid common pitfalls of incorporating spreadsheets into Java apps. Read about it in the free white paper: “Five Biggest Blunders when Building Spreadsheet Applications in JavaDownload Now!
  #1  
Old February 18th, 2004, 03:07 AM
iamvijay iamvijay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 iamvijay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to display 2nd row value of each job as a column value

Hi,

Output from a query is

JOB ENAME
--------- ----------
ANALYST SCOTT
ANALYST FORD
CLERK SMITH
CLERK ADAMS
CLERK MILLER
CLERK JAMES
MANAGER JONES
MANAGER CLARK
MANAGER BLAKE
PRESIDENT KING
SALESMAN ALLEN
SALESMAN MARTIN
SALESMAN TURNER
SALESMAN WARD

I wanted output like below,

JOB ENAME1 ENAME2
--------- ---------- --------
ANALYST SCOTT FORD
CLERK SMITH ADAMS
MANAGER JONES CLARK
PRESIDENT KING
SALESMAN ALLEN MARTIN


ENAME1 - First row value of each job
ENAME2 - Second row value of each job

Ignore if it has more than 2 rows for each job, and if it has only 1 row, put NULL into ENAME2 col.

Thanx in advance

vijay

Last edited by iamvijay : February 18th, 2004 at 03:10 AM.

Reply With Quote
  #2  
Old February 18th, 2004, 04:50 PM
Dan Drillich Dan Drillich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 68 Dan Drillich User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Here you go:

create table tst (

job varchar(40),
ename varchar(40)

)


insert into tst values ('ANALYST','SCOTT')
insert into tst values ('ANALYST','FORD')
insert into tst values ('CLERK','SMITH')
insert into tst values ('CLERK','ADAMS')
insert into tst values ('CLERK','MILLER')
insert into tst values ('CLERK','JAMES')
insert into tst values ('MANAGER','JONES')
insert into tst values ('MANAGER','CLARK')
insert into tst values ('MANAGER','BLAKE')
insert into tst values ('PRESIDENT','KING')
insert into tst values ('SALESMAN','ALLEN')
insert into tst values ('SALESMAN','MARTIN')
insert into tst values ('SALESMAN','TURNER')
insert into tst values ('SALESMAN','WARD')



select job,
max(decode(n,1,ename,null)),
max(decode(n,2,ename,null))
from
(
select * from
(select job, ename, row_number() over (partition by job order by job) n from tst)
where n <= 2
)
group by job

The results are:

JOB MAX(DECODE(N,1,ENAME,NULL)) MAX(DECODE(N,2,ENAME,NULL))

ANALYST ---- SCOTT ---- FORD
CLERK ---- SMITH ---- ADAMS
MANAGER ---- JONES ---- CLARK
PRESIDENT ---- KING ---- (nil)
SALESMAN ---- ALLEN ---- MARTIN

Regards,
Dan

btw, is it work or studies ?

Reply With Quote
  #3  
Old February 18th, 2004, 10:12 PM
iamvijay iamvijay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 iamvijay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanq very much,

Thanq Dan,

it is working,

and btw, this is not for study purpose,

thanx a lot

vijay

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > How to display 2nd row value of each job as a column value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway