I've a got query that is using a group by with sums. I need to select a column twice to display different data but a where only would do the same data. In essence:
Col 1 Col 2 Hours Committed hours
100 Item 100 flag A total flag b total
So for item 100, it would sum up hours from a detail table where flag = a AND sum up hours where flag = b. The hours in the detail table is the same column, just selecting different rows to give me a sum in the committed hours than in the Hours column.
I'm really not sure how to go about this. Any ideas?
Here's my initial script:
SELECT JCJOBCAT.JCAT_PHS_CODE, JCJOBHPHS.JHP_NAME, SUM(DISTINCT JCJOBCAT.JCAT_BUDG_AMT) AS EXPR1, SUM(JCDETAIL.JCDT_AMT) AS EXPR2 FROM JCJOBCAT, JCDETAIL, JCJOBHPHS WHERE JCJOBCAT.JCAT_COMP_CODE = JCDETAIL.JCDT_COMP_CODE AND JCJOBCAT.JCAT_JOB_CODE = JCDETAIL.JCDT_JOB_CODE AND JCJOBCAT.JCAT_PHS_CODE = JCDETAIL.JCDT_PHS_CODE AND (JCJOBCAT.JCAT_PHS_CODE = JCJOBHPHS.JHP_CODE AND JCJOBCAT.JCAT_JOB_CODE = JCJOBHPHS.JHP_JOB_CODE) AND ((JCJOBCAT.JCAT_JOB_CODE = :jc_job_code) AND (JCJOBCAT.JCAT_CODE = 'EQRT')) GROUP BY JCJOBCAT.JCAT_PHS_CODE, JCJOBCAT.JCAT_JOB_CODE, JCJOBHPHS.JHP_NAME
What I want is to add in another jcdetail.jcdt_amt on the same line. One would be where jcdetail.job_type = 'O' and the other colum would be where jcdetail.job_type = 'C'
Col 1 Col 2 Hours Committed hours
100 Item 100 flag A total flag b total
So for item 100, it would sum up hours from a detail table where flag = a AND sum up hours where flag = b. The hours in the detail table is the same column, just selecting different rows to give me a sum in the committed hours than in the Hours column.
I'm really not sure how to go about this. Any ideas?
Here's my initial script:
SELECT JCJOBCAT.JCAT_PHS_CODE, JCJOBHPHS.JHP_NAME, SUM(DISTINCT JCJOBCAT.JCAT_BUDG_AMT) AS EXPR1, SUM(JCDETAIL.JCDT_AMT) AS EXPR2 FROM JCJOBCAT, JCDETAIL, JCJOBHPHS WHERE JCJOBCAT.JCAT_COMP_CODE = JCDETAIL.JCDT_COMP_CODE AND JCJOBCAT.JCAT_JOB_CODE = JCDETAIL.JCDT_JOB_CODE AND JCJOBCAT.JCAT_PHS_CODE = JCDETAIL.JCDT_PHS_CODE AND (JCJOBCAT.JCAT_PHS_CODE = JCJOBHPHS.JHP_CODE AND JCJOBCAT.JCAT_JOB_CODE = JCJOBHPHS.JHP_JOB_CODE) AND ((JCJOBCAT.JCAT_JOB_CODE = :jc_job_code) AND (JCJOBCAT.JCAT_CODE = 'EQRT')) GROUP BY JCJOBCAT.JCAT_PHS_CODE, JCJOBCAT.JCAT_JOB_CODE, JCJOBHPHS.JHP_NAME
What I want is to add in another jcdetail.jcdt_amt on the same line. One would be where jcdetail.job_type = 'O' and the other colum would be where jcdetail.job_type = 'C'