Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Left Outer Join and totals
bbcrock_at_gmail.com wrote:
> I solved the issue. Another classic, "Once I posted it to the
> newsgroup, I was determined to solve it." Our DBA said it was not
> possible, because of the null rows, but of course it was. This code
> works (pseudocode, fyi, so no DDL, just DML and also, Oracle 9i):
>
> select Team.teamname, count(Report_ID)
> from Team LEFT OUTER JOIN Report
> ON Team.TeamID = Report.TeamID
> group by team.teamname
>
> Was hung up on the count(*)- that caused the bad results. running the
> count on report_id solved it.
>
> thanks!
>
SELECT t.teamname, NVL (v.cnt, 0) cnt
FROM team t,
(SELECT teamid, COUNT (*) cnt FROM report GROUP BY teamid) v
Syntax may not be 100% right since I haven't tested it, but it should point you in the right direction. Received on Mon May 22 2006 - 15:11:04 CDT