View previous topic :: View next topic
|
Author |
Message |
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Hi,
I have a table T .I have 5 Dept sat D1 to D5 .I have find the max sal in each dept .Could you please let me know the DB2 query for the same |
|
Back to top |
|
|
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Select max (sal) from T1
Where t1.dept = ( select dept from T1 a where T1.sal = a.sal)
Whether the above query is right |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Below query will give you desired result.
Code: |
SELECT dept,MAX(sal)
FROM T1 GROUP BY dept;
|
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Is it an Interview question? I'd like to move it there... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Anuj,
I'd flip a coin to choose between an interview question and homework
Happy New Year!
d |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
l.nethaji wrote: |
Whether the above query is right |
What is this, a mainframe guessing forum. If you have NOT tested something then either state quite categorically that it is not tested and the logic used behind your post, or better still DO NOT POST AT ALL |
|
Back to top |
|
|
l.nethaji
New User
Joined: 16 Mar 2008 Posts: 90 Location: tamil nadu
|
|
|
|
Hi,
As i am working in a IDMS database i amnot able to practice it in Db2 environment.
I just want to make sure the logic is right in the above query
That the reason behind why i mentioned it as a questionary.
Thanks,
L.Nethaji |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
As i am working in a IDMS database i amnot able to practice it in Db2 environment. |
Would have been a good idea to mention this in the original post. . . . |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Quote: |
Would have been a good idea to mention this in the original post. . . . |
Not if it happens to be psychic day. |
|
Back to top |
|
|
|