Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Group by problem
If I understand correctly, you want the value of count to be 0 when there is no corresponding row in table b? Here is an example using the DEPT and EMP tables showing different count approaches. Note that for DEPTNO = 40, there are no EMP rows:
1 select d.deptno, count(*), count(d.deptno), count(e.deptno)
2 from emp e, dept d
3 where d.deptno = e.deptno (+)
4* group by d.deptno
SQL> /
DEPTNO COUNT(*) COUNT(D.DEPTNO) COUNT(E.DEPTNO)
---------- ---------- --------------- ---------------
10 3 3 3 20 5 5 5 30 6 6 6 40 1 1 0
Notice the differences for DEPTNO = 40. So, is it count(b.column2) that you are looking for, similar to the count(e.deptno) above?
Regards,
Larry G. Elkins
elkinsl_at_flash.net
214.954.1781
> -----Original Message-----
> From: root_at_fatcity.com [mailto:root_at_fatcity.com]On Behalf Of Csillag
> Zsolt
> Sent: Friday, October 05, 2001 12:50 PM
> To: Multiple recipients of list ORACLE-L
> Subject: Group by problem
>
>
> Hi,
>
> If I have the following query:
>
> Select a.column1, count(*)
>
> from a, b
>
> where a.column2 = b.column2
>
> It works correctly, it displays the correct number in the count.
>
> However there are records that don't meet the criteria 'where
> a.column2 =
> b.column2'
>
> So I modified the query:
>
> Select a.column1, count(*)
>
> from a, b
>
> where a.column2 = b.column2(+)
>
> Now with (+) it displays every record, but the problem is that
> in case there is no relation, the count displays 1 instead of 0.
> In other cases it is good.
>
> But I can't decide from the program if it's 1 because it had 1
> relation in
> table b, or 1 because it hadn't
> got any relation.
>
> Can you help me work around this problem?
>
>
> Thank you
>
>
>
>
> Zsolt Csillag
> Hungary
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Csillag Zsolt
> INET: starsoft_at_interware.hu
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Larry Elkins INET: elkinsl_at_flash.net Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Fri Oct 05 2001 - 12:39:47 CDT
![]() |
![]() |