We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,078 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Unable to understand some SQL Queries

Hi there

How are you?
Would you please explain how the following queries work

//alternate rows
select * from emp where rowid in (select decode(mod(rownum,2),0,rowid, null) from emp); 

//3rd max salary
select distinct sal from emp e1 where 3 = (select count(distinct sal) from emp e2 where e1.sal <= e2.sal); 

//top n
select * from emp where rownum <= &n; 

//bottom n
select * from emp minus select * from emp where rownum <= (select count(*) - &n from emp); 

Thank you

2
Contributors
2
Replies
11 Hours
Discussion Span
2 Months Ago
Last Updated
16
Views
ripplex
Newbie Poster
10 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

What database are you using? Can you show the table structure for emp?

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,460
Skill Endorsements: 86

EMP table has two attributes viz. empno(varchar2(10)) and empname(varchar2(10)).

ripplex
Newbie Poster
10 posts since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0557 seconds using 2.65MB