Hello all,
I've been working on a query and I'm attempting to shorten the results. Without the count or sum functions, I get 450 records. When I use the count or sum functions, I shorten the amount of records, but the function isn't doing what I need it to. I have a feeling it is the way I am using these functions. Here is the query:
SELECT DISTINCT A.EMPLID, A.NAME, A.PAYGROUP, A.DEPTID, B.ERNCD, C.DESCR, B.RATE_USED, COUNT(B.OTH_HRS) AS OTH_HRS,
B.OTH_PAY, SUM(B.OTH_EARNS) AS OTH_EARNS, B.PAY_END_DT
FROM PS_PAY_CHECK A INNER JOIN PS_PAY_OTH_EARNS B
ON A.COMPANY = B.COMPANY
AND A.PAYGROUP = B.PAYGROUP
AND A.EMPLID = '000012226'
AND A.DEPTID = '799400'
AND B.ERNCD = 'SKH'
AND B.PAY_END_DT BETWEEN '2007-01-01' AND CURRENT DATE
LEFT OUTER JOIN PS_EARNINGS_TBL C
ON B.ERNCD = C.ERNCD
WHERE C.EFFDT = (SELECT MAX (C1.EFFDT)
FROM PS_EARNINGS_TBL C1
WHERE C.ERNCD = C1.ERNCD
AND C1.EFFDT <= CURRENT DATE)
GROUP BY A.EMPLID, A.NAME, A.PAYGROUP, A.DEPTID, B.ERNCD, C.DESCR, B.RATE_USED, B.OTH_PAY, B.PAY_END_DT
My results are really scewed when I run it. For example, these are the results without the functions:
NAME PAYGROUP DEPTID ERNCD OTH_HRS OTH_EARNS PAY_END_DT
Torres,Efren CW3 799400 SKH 8.00 0.00 2007-01-07
Torres,Efren CW3 799400 SKH 16.00 0.00 2007-01-07
Torres,Efren CW3 799400 SKH 8.00 148.00 2007-01-07
Torres,Efren CW3 799400 SKH 8.00 196.96 2007-01-07
Torres,Efren CW3 799400 SKH 16.00 424.00 2007-01-07
These are the results with the functions:
NAME PAYGROUP DEPTID ERNCD OTH_HRS OTH_EARNS PAY_END_DT
Torres,Efren CW3 799400 SKH 7616.00 104578.56 2007-01-07
Torres,Efren CW3 799400 SKH 23392.00 174910.96 2007-01-14
Torres,Efren CW3 799400 SKH 5712.00 39236.00 2007-01-21
Torres,Efren CW3 799400 SKH 23528.00 219018.48 2007-01-28
As you can see for the PAY_END_DT, the amounts are incorrect. Any suggestions? Thank you much.
I've been working on a query and I'm attempting to shorten the results. Without the count or sum functions, I get 450 records. When I use the count or sum functions, I shorten the amount of records, but the function isn't doing what I need it to. I have a feeling it is the way I am using these functions. Here is the query:
SELECT DISTINCT A.EMPLID, A.NAME, A.PAYGROUP, A.DEPTID, B.ERNCD, C.DESCR, B.RATE_USED, COUNT(B.OTH_HRS) AS OTH_HRS,
B.OTH_PAY, SUM(B.OTH_EARNS) AS OTH_EARNS, B.PAY_END_DT
FROM PS_PAY_CHECK A INNER JOIN PS_PAY_OTH_EARNS B
ON A.COMPANY = B.COMPANY
AND A.PAYGROUP = B.PAYGROUP
AND A.EMPLID = '000012226'
AND A.DEPTID = '799400'
AND B.ERNCD = 'SKH'
AND B.PAY_END_DT BETWEEN '2007-01-01' AND CURRENT DATE
LEFT OUTER JOIN PS_EARNINGS_TBL C
ON B.ERNCD = C.ERNCD
WHERE C.EFFDT = (SELECT MAX (C1.EFFDT)
FROM PS_EARNINGS_TBL C1
WHERE C.ERNCD = C1.ERNCD
AND C1.EFFDT <= CURRENT DATE)
GROUP BY A.EMPLID, A.NAME, A.PAYGROUP, A.DEPTID, B.ERNCD, C.DESCR, B.RATE_USED, B.OTH_PAY, B.PAY_END_DT
My results are really scewed when I run it. For example, these are the results without the functions:
NAME PAYGROUP DEPTID ERNCD OTH_HRS OTH_EARNS PAY_END_DT
Torres,Efren CW3 799400 SKH 8.00 0.00 2007-01-07
Torres,Efren CW3 799400 SKH 16.00 0.00 2007-01-07
Torres,Efren CW3 799400 SKH 8.00 148.00 2007-01-07
Torres,Efren CW3 799400 SKH 8.00 196.96 2007-01-07
Torres,Efren CW3 799400 SKH 16.00 424.00 2007-01-07
These are the results with the functions:
NAME PAYGROUP DEPTID ERNCD OTH_HRS OTH_EARNS PAY_END_DT
Torres,Efren CW3 799400 SKH 7616.00 104578.56 2007-01-07
Torres,Efren CW3 799400 SKH 23392.00 174910.96 2007-01-14
Torres,Efren CW3 799400 SKH 5712.00 39236.00 2007-01-21
Torres,Efren CW3 799400 SKH 23528.00 219018.48 2007-01-28
As you can see for the PAY_END_DT, the amounts are incorrect. Any suggestions? Thank you much.