Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Return Multiple different counts in One Query.

user10719205Dec 8 2015 — edited Dec 8 2015

Hi All,

I have queries where I just get the counts, and was wondering how to return multiple counts in one query ??

Here is the code:

Query Count 1

SELECT count(*) AS CNT_A_NOTIN_B FROM (

               -- A NOT IN B

              SELECT 'P' AS REC_TYPE,

                      'BEFORE' AS VALTN,

                      M.PENSN_PLAN_SID AS PENSN_PLAN_SID,

                     M.CLIENT_SID AS CID

              FROM    (SELECT * FROM TABLE1

                      WHERE VALTN_JOB_NR = 11

                      AND (nvl(TOTAL_PV, 0) > 0 OR (0 > 0 AND NVL(TOTAL_PV, 0) > 0))

                      ) M

              WHERE   (M.PENSN_PLAN_SID, M.CLIENT_SID) NOT IN (SELECT PENSN_PLAN_SID, CLIENT_SID

                                                              FROM TABLE1

                                                              WHERE VALTN_JOB_NR = 12)

          ) Q ;

Query Count 2

SELECT count(*) AS CNT_B_NOTIN_A FROM (

              SELECT 'P' AS REC_TYPE,

                      'AFTER' AS VALTN,

                      S.PENSN_PLAN_SID AS PENSN_PLAN_SID,

                      S.CLIENT_SID AS CLIENT_SID

              FROM    (SELECT * FROM TABLE1

                      WHERE VALTN_JOB_NR = 12

                      AND (nvl(TOTAL_PV, 0) > 0 OR (0 > 0 AND NVL(TOTAL_PV, 0) > 0))

                      ) S

              WHERE (S.PENSN_PLAN_SID, S.CLIENT_SID) NOT IN (SELECT PENSN_PLAN_SID, CLIENT_SID

                                                                FROM IPVOWN.TABLE1

                                                                WHERE VALTN_JOB_NR = 11)

          ) D

As you can see above, I have 2 queries that return just the count, I would like the output to be just like below:

CNT_A_NOTIN_B | CNT_B_NOTIN_A

      1578               |         100

I tried UNION, but that didnt work, I got both counts like below, which not what I want.

CNT_A_NOTIN_B

       1578

       100


Thanks in Advance, your help is much appreciated.

_B

BotggdsfsdfsdfUNIONsdfsdfdfh

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2016
Added on Dec 8 2015
3 comments
1,106 views