MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » August 2009

RE: Need help with SQL group by



fixed

Sorry, forgot to take out plbbg1 out of the group by:

SELECT eeun, eedpt, plbemp, eenam, max(plbbg1) as plbbg1, plbhrs , plbptp
FROM PRLBH, EEMP WHERE PLBEMP = EEENO and
PLBPTP in('CO','OH', '6D','7D','OG') and
EETDT = 0 and EEDPT = '081' and PLBWDT = 20090115
GROUP BY PLBEMP,EENAM, PLBHRS , PLBPTP,EEUN, EEDPT
Order by PLBEMP

Elvis


Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Elvis Budimlic
Sent: Monday, August 17, 2009 11:16 AM
To: 'Midrange Systems Technical Discussion'
Subject: RE: Need help with SQL group by

Do you care what value of plbbg1 is selected for the duplicate employee
record?
If not, then use any of the aggregate functions to 'pick' one, i.e.:

SELECT eeun, eedpt, plbemp, eenam, max(plbbg1) as plbbg1, plbhrs , plbptp
FROM PRLBH, EEMP WHERE PLBEMP = EEENO and
PLBPTP in('CO','OH', '6D','7D','OG') and
EETDT = 0 and EEDPT = '081' and PLBWDT = 20090115
GROUP BY PLBEMP,EENAM,PLBBG1, PLBHRS , PLBPTP,EEUN, EEDPT
Order by PLBEMP

Hth, Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
Subject: Need help with SQL group by

I have a sql statement that I cannot get to work the way I want.
The statement as it currently exists is.
SELECT eeun, eedpt, plbemp, eenam, plbbg1, plbhrs , plbptp
FROM PRLBH, EEMP WHERE PLBEMP = EEENO and
PLBPTP in('CO','OH', '6D','7D','OG') and
EETDT = 0 and EEDPT = '081' and PLBWDT = 20090115
GROUP BY PLBEMP,EENAM,PLBBG1, PLBHRS , PLBPTP,EEUN, EEDPT
Order by PLBEMP

My results look like this

Eeun eedpt plbemp eenam plbbg1 plbhrs plbptp
Y 081 890 Smith, Mike 081 4.00 OH
Y 081 890 Smith, Mike 081 1.00 OH
Y 081 1160 Mead,Kurt 081 3.50 OH
Y 081 1160 Mead,Kurt 081 1.50 OH

I am trying to get 1 record per employee, but I cannot find the correct
solution.
What am I missing here?

Mike








Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact