Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
SQL Query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
babuprasad_g
Currently Banned

New User


Joined: 26 May 2005
Posts: 45
Location: gurgaon

PostPosted: Tue Dec 27, 2005 6:42 pm    Post subject: SQL Query
Reply with quote

Hi folks,

There are 5 departments for each department there is few no of employees.
Extract all the employees for each departments Condition is( salary is greater than average salary of each department).

Please give me the query for this question.


Thanks & Regards
Prasad
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Tue Dec 27, 2005 7:30 pm    Post subject: Re: SQL Query
Reply with quote

Code:
SELECT EMP, SAL FROM <TABLE> WHERE SAL >
(SELECT AVG(SAL) FROM <TABLE> WHERE DEPT= 'first') AND DEPT= 'first';
UNION         
SELECT EMP, SAL FROM <TABLE> WHERE SAL >
(SELECT AVG(SAL) FROM <TABLE> WHERE DEPT= 'second') AND DEPT= 'second';
UNION
SELECT EMP, SAL FROM <TABLE> WHERE SAL >
(SELECT AVG(SAL) FROM <TABLE> WHERE DEPT= 'third') AND DEPT= 'third';
UNION
SELECT EMP, SAL FROM <TABLE> WHERE SAL >
(SELECT AVG(SAL) FROM <TABLE> WHERE DEPT= 'fourth') AND DEPT= 'fourth';
UNION
SELECT EMP, SAL FROM <TABLE> WHERE SAL >
(SELECT AVG(SAL) FROM <TABLE> WHERE DEPT= 'fifth') AND DEPT= 'fifth';


The query above will extract all the employees having more than AVG salary dept wise....

Regards,

Priyesh.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Tue Dec 27, 2005 7:40 pm    Post subject: Query
Reply with quote

Hi frnd,

Code:
select ename from employee where sal>=(select avg(sal) a from dept);


Use the above query
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Tue Dec 27, 2005 7:49 pm    Post subject: Re: SQL Query
Reply with quote

Quote:
_________________
CORRECT ME IF I M WRONG


khamarutheen....Is that your permanent Signature Line.

Not sure, If I misinterpreted the requirements...Well, If I did, your query seems to be very effiecient on TIME as well as CPU utilization.

Regards,

Priyesh.
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 680
Location: NJ

PostPosted: Tue Dec 27, 2005 7:57 pm    Post subject: query
Reply with quote

Hi priyesh,

Quote:
Is that your permanent Signature Line.


S. since i wanna to enter each time while solving the problem. i made as permanent... icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us