Telling how many records are joined

Поиск
Список
Период
Сортировка
От Andrew Perrin
Тема Telling how many records are joined
Дата
Msg-id Pine.LNX.4.21L1.0201041123310.749-100000@nujoma.perrins
обсуждение исходный текст
Список pgsql-sql
Greetings-

I'm sure there's a (moderately) simple answer to this, but I'd love some
help with it.

I have a database with four tables:

papers  -  information about newspapers, including a unique paperid
letters -  information and text of letters to the editors, including    a unique paperid and the paperid in which it
appeared
patterns-  word patterns occurring in one or more letters, including    a unique patternid
pattern_occurrences - a linking table containing a letterid, a patternid,                and a count (the number of
timesthe pattern occurs                      in the letter).
 

The patterns and pattern_occurrences tables are quite large (around 3
million records each).

I'd like to know, for example, how many letters from each paper have one
or more patterns already coded. The best I can do is:

SELECT papercode, count(papercode) FROM papers, letters
WHERE papers.paperid=letters.paperid AND
letters.letterid IN (SELECT DISTINCT o_letterid FROM pattern_occurrences) 
GROUP BY papercode;

Thanks for any advice.

----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin@unc.edu - http://www.unc.edu/~aperrinAssistant Professor of Sociology, U of North
Carolina,Chapel Hill     269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA
 




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

Предыдущее
От: Masaru Sugawara
Дата:
Сообщение: Re: left join and where
Следующее
От: Frank Bax
Дата:
Сообщение: simple? join