Question About Aggregate Functions

Поиск
Список
Период
Сортировка
От Don Parris
Тема Question About Aggregate Functions
Дата
Msg-id 1eba300b0609120947g4ad9890ay92a3bb4a2799afc5@mail.gmail.com
обсуждение исходный текст
Список pgsql-novice
Greetings,

I'm a DB novice as well as a pgsql novice.  I can manage to run a few basic queries, but that's all I've really done so far.  How do I create a query that (1) evaluates each boolean field for TRUE/FALSE and (2) counts the number of rows where each field is TRUE?  Also, one field is an integer, so I want the average from that field, rather than the count.  Something along the lines of:

SELECT COUNT (t1.fielda, t2.fielda, t2.fieldb) AVG(t2.fieldc) FROM t1, t2
WHERE t1.item_id=t2.item_id AND t1.fielda IS TRUE  AND t2.fielda IS TRUE AND t2.fieldb IS TRUE AND t2.fieldc IS NOT NULL

The result is intended to be something of a summary report.  t1 contains basic info about each item, with one field for whether the item is active or not.  The other table contains additional info about whether each item has particular attributes.  I want the query to tell me the average number of years active items have been active, and the number of items where each attribute is true.  I then want to turn the raw attribute counts into percentages, so I can say "for n% of the items these attributes are true".

Pointers to good examples/tutorials are welcome.  Most I have seen are rather simplistic, and what I am reading in the manual isn't coming together very well.

Thanks,
Don

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

Предыдущее
От: "Elias Chavarria"
Дата:
Сообщение: suscribe please
Следующее
От: "Don Parris"
Дата:
Сообщение: Re: Question About Aggregate Functions