1,105,221 Community Members

Unable to understand some SQL Queries

Member Avatar
ripplex
Newbie Poster
10 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,285 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,829 [?]
Skill Endorsements: 154 [?]
Moderator
Featured
Sponsor
 
0
 

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

Member Avatar
ripplex
Newbie Poster
10 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article