Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with Group By clause

Re: Help with Group By clause

From: DA Morgan <damorgan_at_exesolutions.com>
Date: Sun, 09 Mar 2003 23:54:17 -0800
Message-ID: <3E6C44A9.8EB55290@exesolutions.com>


Randy Harris wrote:

> I seem to have gotten it working with (again simplified)
>
> SELECT C.CustomerID, C.Name, C.Address, COUNT(V.VisitID) as VCount
> FROM CustomerTable C, VisitsTable V
> WHERE C.CustomerID=V.CustomerID(+);
> GROUP BY C.CustomerID, C.Name, C.Address
>
> Is this the "correct" way to do it?
>
> --
> Randy Harris
>
> "Randy Harris" <randy.harris_at_nospam.net> wrote in message
> news:OTUaa.5905$se1.3188022_at_newssvr28.news.prodigy.com...
> > I believe this can be done, but I am SQL challenged and would appreciate
> > help.
> >
> > I need to return several fields and the count of related records in
> another
> > table. It is simplified here:
> >
> > CustomerTable
> > CustomerID
> > Name
> > Address
> >
> > VisitsTable
> > CustomerID
> > VisitID
> >
> > This, of course, doesn't work, I think it needs a GROUP BY clause:
> >
> > SELECT C.CustomerID, C.Name, C.Address, COUNT(V.VisitID)
> > FROM CustomerTable C, VisitsTable V
> > WHERE C.CustomerID=V.CustomerID(+);
> >
> > Thanks in advance for your help,
> > --
> > Randy Harris
> >
> >
> >

Yes.

GROUP BY all non-aggregated fields in the SELECT clause.

Daniel Morgan Received on Mon Mar 10 2003 - 01:54:17 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US