Обсуждение: RE: [SQL] problem with join & count

Поиск
Список
Период
Сортировка

RE: [SQL] problem with join & count

От
"Jackson, DeJuan"
Дата:
try:
SELECT t1.name, count(t2.tag)
  FROM t1, t2
 WHERE t1.number = t2.number
 GROUP BY t1.number, t1.name

    -DEJ

> -----Original Message-----
> From: pat@patoche.org [mailto:pat@patoche.org]
> Sent: Thursday, February 04, 1999 2:39 PM
> To: pgsql-sql@postgreSQL.org
> Subject: [SQL] problem with join & count
>
>
> Hi,
>
> I don't succeed to build an SQL to do the task i describe below.
> If someone can helps, thanks in advance.
>
> I have two tables
>
> number  | name
> --------------
>  1      | toto
>  2      | titi
>  3      | tutu
>
> (here the number is a primary key)
>
> and
>
> number  |  tag
> ---------------
>  1      | alpha
>  1      | beta
>  2      | gamma
>  3      | zeta
>  3      | epsilon
>
> the number in the left column is the same of the number in
> the first table,
> but can appear in that second table many times.
>
> i need an sql query that will return:
>
> name   |  how_often
> -------------------
>  toto  | 2
>  titi  | 1
>  tutu  | 2
>
> that is, the result table should contain all names present in
> the first table
> and then the number of times the number associated with the
> name appears in
> the second table.
>
> Thanks a lot for your help.
>
> Patrick
>
> /\//\/\/\\/\/\//\/\\/\/\\/\\/\//\/\\/\//\/\\/\//\/\\/\//\/\\
> Patrick M.   pat@patoche.org    http://www.patoche.org/
>
>

Re: [SQL] problem with join & count

От
Dimitri
Дата:
Jackson, DeJuan wrote:
>
> try:
> SELECT t1.name, count(t2.tag)
>   FROM t1, t2
>  WHERE t1.number = t2.number
>  GROUP BY t1.number, t1.name
______________^
your query will never work :)), you have to miss t1.number...

Best regards!
(dim)

>
>         -DEJ
>
> > -----Original Message-----
> > From: pat@patoche.org [mailto:pat@patoche.org]
> > Sent: Thursday, February 04, 1999 2:39 PM
> > To: pgsql-sql@postgreSQL.org
> > Subject: [SQL] problem with join & count
> >
> >
> > Hi,
> >
> > I don't succeed to build an SQL to do the task i describe below.
> > If someone can helps, thanks in advance.
> >
> > I have two tables
> >
> > number  | name
> > --------------
> >  1      | toto
> >  2      | titi
> >  3      | tutu
> >
> > (here the number is a primary key)
> >
> > and
> >
> > number  |  tag
> > ---------------
> >  1      | alpha
> >  1      | beta
> >  2      | gamma
> >  3      | zeta
> >  3      | epsilon
> >
> > the number in the left column is the same of the number in
> > the first table,
> > but can appear in that second table many times.
> >
> > i need an sql query that will return:
> >
> > name   |  how_often
> > -------------------
> >  toto  | 2
> >  titi  | 1
> >  tutu  | 2
> >
> > that is, the result table should contain all names present in
> > the first table
> > and then the number of times the number associated with the
> > name appears in
> > the second table.
> >
> > Thanks a lot for your help.
> >
> > Patrick
> >
> > /\//\/\/\\/\/\//\/\\/\/\\/\\/\//\/\\/\//\/\\/\//\/\\/\//\/\\
> > Patrick M.   pat@patoche.org    http://www.patoche.org/
> >
> >

--
=====================================================
 Dimitri KRAVTCHUK  (dim)           Sun Microsystems
 Benchmark Engineer                 France
 dimitri@France.Sun.COM
=====================================================

ANNOUNCEMENT...SQL-Ledger 0.1.1

От
Thomas Good
Дата:
Hi all,

I am working on a project called SQL-Ledger.  We are a spin off of the
now defunct FreeMoney project.  Anyone interested may have a look (and
grab our initial release) at:

http://www.simtax.ca/acc

This is an accounting package for apache-perl(Pg)-postgresql.
We are using libpq at the moment but plan to migrate to dbi soon.
Anyone wishing to contribute is welcome!

Cheers,
Tom
----
         North Richmond Community Mental Health Center

         Thomas Good   Information Systems Coordinator
         E-Mail:       tomg@ { admin | q8 } .nrnet.org
         Phone:        718-354-5528
         Fax:          718-354-5056

                 Empowered by PostgreSQL 6.3.2