problem with join & count

Поиск
Список
Период
Сортировка
От pat@patoche.org
Тема problem with join & count
Дата
Msg-id 199902042039.VAA00553@vagabond.bde.espci.fr
обсуждение исходный текст
Ответы Re: [SQL] problem with join & count
Список pgsql-sql
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/


В списке pgsql-sql по дате отправления:

Предыдущее
От: George Moga
Дата:
Сообщение: Re: [SQL] using matches on int4
Следующее
От: Michael Olivier
Дата:
Сообщение: Re: [SQL] keeping OID's when copying table