IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Is it possible to code a query in Having clause??


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sakthi_ksv

New User


Joined: 20 Jul 2006
Posts: 48
Location: Chennai

PostPosted: Mon Jul 23, 2007 10:35 am
Reply with quote

Hi,

I was asked in an interview that is it possible to code a query in having clause?? is it possible??

Thanks,
Sakthi.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Jul 23, 2007 10:43 am
Reply with quote

Sakthi,

Quote:
I was asked in an interview that is it possible to code a query in having clause?? is it possible??

Yes it is possible.
Back to top
View user's profile Send private message
sakthi_ksv

New User


Joined: 20 Jul 2006
Posts: 48
Location: Chennai

PostPosted: Mon Jul 23, 2007 1:14 pm
Reply with quote

OK thanks. Can I have a result for the following question.
I have a EMP table with the following columns

EMPNO
EMPNAME
DEPT
SALARY
AGE

I was asked a question like this. 'List out all the departments with Max salary and min age in each depart.

Example is

Department MaxSal MinAge

Manager 100000 29


Could anyone tell me the query for this.

Thanks in advance,
Sakthi
Back to top
View user's profile Send private message
amitava
Warnings : 1

Active User


Joined: 30 Oct 2005
Posts: 186
Location: India

PostPosted: Mon Jul 23, 2007 3:46 pm
Reply with quote

Hey Shakti,
I think the following SQL can do the ourpose what you are looking for -
Code:

SELECT DEPT, MAX(SALARY), MIN(AGE) FROM <TABLE NAME> GROUP BY DEPT


By this it should fetch the max salary and min age for department.

Correct me if I misunderstood your query.


Regards,

Amitava
icon_wink.gif
Back to top
View user's profile Send private message
sreenivasreddyg

New User


Joined: 23 Apr 2005
Posts: 39
Location: delhi

PostPosted: Mon Jul 23, 2007 6:17 pm
Reply with quote

It should work
Back to top
View user's profile Send private message
sakthi_ksv

New User


Joined: 20 Jul 2006
Posts: 48
Location: Chennai

PostPosted: Mon Jul 23, 2007 6:33 pm
Reply with quote

ok thanks for quick response. If it should work then I am correct. Also the next question I was asked was to select the EMPNO for each department that will be the output of the above query. ie select EMPNO of the employees of each department who has the maximum salary and with minimum age. what will be the query for this.
Back to top
View user's profile Send private message
amitava
Warnings : 1

Active User


Joined: 30 Oct 2005
Posts: 186
Location: India

PostPosted: Tue Jul 24, 2007 10:20 am
Reply with quote

Hey Sakthi,
I think it is no way possible to fetch the empno also for the max(salary) and min(age) for each dept because there may be cases where more than one person are getting the maximum salary at minimum age. If that is that, then how you are going to fetch from the table?

icon_razz.gif Correct me if I am wrong icon_wink.gif
Back to top
View user's profile Send private message
sakthi_ksv

New User


Joined: 20 Jul 2006
Posts: 48
Location: Chennai

PostPosted: Tue Jul 24, 2007 11:52 am
Reply with quote

hi Amitava,
you are right. In that case you should display both the rows. If it is not possible it should display only one row.

Thanks and Regards,
Sakthi.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
Search our Forums:

Back to Top