Question : Oracle - Join sql output from 2 sql statements with 2 different kinds of where and select statements

I would like to join the 2 attached statements in one sql statement and have the following output:
Type - Change Group - Total - Cancelled

Is this possible? If yes, how?

1:
2:
3:
select p.ts_name "Type", g.ts_title "Change Group", count(rfc.ts_id) "Total" from usr_rfc rfc, u_group_codes g, ts_projects p where g.ts_id = rfc.ts_group_code and rfc.ts_projectid = p.ts_id and to_char(to_date('01-JAN-1970','DD-MON-YYYY') + ( rfc.ts_submitdate / (60 * 60 * 24) ),'YYYY') = 2010 and to_char(to_date('01-JAN-1970','DD-MON-YYYY') + ( rfc.ts_submitdate / (60 * 60 * 24) ),'Q') = 2 group by p.ts_name, g.ts_title order by p.ts_name, g.ts_title;

select p.ts_name "Type", g.ts_title "Change Group", count(rfc.ts_id) "Cancelled" from usr_rfc rfc, u_group_codes g, ts_projects p where g.ts_id = rfc.ts_group_code and rfc.ts_projectid = p.ts_id and rfc.ts_state in (4,195) and to_char(to_date('01-JAN-1970','DD-MON-YYYY') + ( rfc.ts_submitdate / (60 * 60 * 24) ),'YYYY') = 2010 and to_char(to_date('01-JAN-1970','DD-MON-YYYY') + ( rfc.ts_submitdate / (60 * 60 * 24) ),'Q') = 2 group by p.ts_name, g.ts_title order by p.ts_name, g.ts_title;

Answer : Oracle - Join sql output from 2 sql statements with 2 different kinds of where and select statements

Try this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
SELECT   ts_name "Type", ts_title "Change Group", SUM (total) "Total", SUM (cancelled) "Cancelled"
    FROM (SELECT   p.ts_name g.ts_title COUNT (rfc.ts_id) Total,
                   0 Cancelled
              FROM usr_rfc rfc, u_group_codes g, ts_projects p
             WHERE g.ts_id = rfc.ts_group_code
               AND rfc.ts_projectid = p.ts_id
               AND TO_CHAR (  TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
                            + (rfc.ts_submitdate / (60 * 60 * 24)),
                            'YYYY'
                           ) = 2010
               AND TO_CHAR (  TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
                            + (rfc.ts_submitdate / (60 * 60 * 24)),
                            'Q'
                           ) = 2
          GROUP BY p.ts_name, g.ts_title
          UNION
          SELECT   p.ts_name , g.ts_title , 0 Total,
                   COUNT (rfc.ts_id) Cancelled
              FROM usr_rfc rfc, u_group_codes g, ts_projects p
             WHERE g.ts_id = rfc.ts_group_code
               AND rfc.ts_projectid = p.ts_id
               AND rfc.ts_state IN (4, 195)
               AND TO_CHAR (  TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
                            + (rfc.ts_submitdate / (60 * 60 * 24)),
                            'YYYY'
                           ) = 2010
               AND TO_CHAR (  TO_DATE ('01-JAN-1970', 'DD-MON-YYYY')
                            + (rfc.ts_submitdate / (60 * 60 * 24)),
                            'Q'
                           ) = 2
          GROUP BY p.ts_name, g.ts_title)
group by ts_name, ts_title
ORDER BY 1, 2
Random Solutions  
 
programming4us programming4us