Ok, I got two tables. On is job detail table. In the Job detail table there is an amount field JCDT_AMT, a Job Number Field JCDT_JOB_NUM, a job control number field JCDT_JOB_CTRL_CODE, and a Job Type Field JCDT_JOB_TYPE.
In the other table is the project managers and their job numbers. PROJMAN and Job_CODE.
I need sum up job amounts where job_type = c and where job_type = b. It has to join JOB_NUM in either JCDT_JOB_CODE or JCDT_JOB_CTRL_CODE. If it's JCDT_Job_code, the JOB_CTRL_CODE = 'ALL' but sometimes it only matches with JOB_CTRL_CODE.
Oh and I want to be able to break it up by a selected POST_DATE (also in the job detail table.)
I don't want the job numbers, I just want one line that will do it. Here's what I got:
The problem is that the numbers are wrong. Upon further checks, I find that when a record is selected where JCDT_JOB_CODE = UETD_JOB_CODE, that record has JCDT_JOB_CTRL_CODE = 'ALL'. So the the sum for that job number is correct. But when I need to link it with the JOB_CTRL_NUM, then the sum comes up quadruple what it should be.
I've played with case statements, but they don't seem to work after the where clause. Union also doesn't seem to work with grouped-queries. I've even used DISTINCT but got the same results. Umm.. HALP!
Thanks!
In the other table is the project managers and their job numbers. PROJMAN and Job_CODE.
I need sum up job amounts where job_type = c and where job_type = b. It has to join JOB_NUM in either JCDT_JOB_CODE or JCDT_JOB_CTRL_CODE. If it's JCDT_Job_code, the JOB_CTRL_CODE = 'ALL' but sometimes it only matches with JOB_CTRL_CODE.
Oh and I want to be able to break it up by a selected POST_DATE (also in the job detail table.)
I don't want the job numbers, I just want one line that will do it. Here's what I got:
Code:
SELECT UETD_PROJECTPER.PROJECTMAN, SUM(decode(JCDETAIL.JCDT_TYPE_CODE, 'B', JCDETAIL.JCDT_AMT, 0)) AS BILLED, SUM(decode(JCDETAIL.JCDT_TYPE_CODE, 'C', JCDETAIL.JCDT_AMT, 0)) AS C_SUM, JCDETAIL.JCDT_JOB_CODE
FROM UETD_PROJECTPER, JCDETAIL
WHERE (UETD_PROJECTPER.JOB_CODE = JCDETAIL.JCDT_JOB_CTRL_CODE OR
UETD_PROJECTPER.JOB_CODE = JCDETAIL.JCDT_JOB_CODE) AND (JCDETAIL.JCDT_POST_DATE < TO_DATE('1/1/2007', 'MM/DD/YYYY')) AND
(JCDETAIL.JCDT_POST_DATE >= TO_DATE('1/1/2006', 'MM/DD/YYYY'))
GROUP BY UETD_PROJECTPER.PROJECTMAN
ORDER BY UETD_PROJECTPER.PROJECTMAN
The problem is that the numbers are wrong. Upon further checks, I find that when a record is selected where JCDT_JOB_CODE = UETD_JOB_CODE, that record has JCDT_JOB_CTRL_CODE = 'ALL'. So the the sum for that job number is correct. But when I need to link it with the JOB_CTRL_NUM, then the sum comes up quadruple what it should be.
I've played with case statements, but they don't seem to work after the where clause. Union also doesn't seem to work with grouped-queries. I've even used DISTINCT but got the same results. Umm.. HALP!
Thanks!