Re: Not able to understand how to write group by

Поиск
Список
Период
Сортировка
От David G Johnston
Тема Re: Not able to understand how to write group by
Дата
Msg-id 1404328703594-5810279.post@n5.nabble.com
обсуждение исходный текст
Ответ на Re: Not able to understand how to write group by  (jared <afonit@gmail.com>)
Ответы Re: Not able to understand how to write group by  (Arup Rakshit <aruprakshit@rocketmail.com>)
Re: Not able to understand how to write group by  (Arup Rakshit <aruprakshit@rocketmail.com>)
Список pgsql-general
afonit wrote
>> gender    participants       answer1_avg   answer2_avg
>> n                      3                     12                  3
>> m                      5                     4                  12
>> f                       7                    15                    23

Are you sure this is what you want?

Since there are two columns you will have to either use a CASE or a
sub-select to facilitate calculating the values for each of the columns.

SELECT gender, answer1_avg, answer2_avg
FROM (SELECT DISTINCT gender FROM ...) gn
LEFT JOIN (SELECT gender, answer1_avg FROM ...) ans1 USING (gender)
LEFT JOIN (SELECT gender, answer2_avg FROM ...) ans2 USING (gender)

You could also try learning "crosstab" from the "tablefunc" extension:

http://www.postgresql.org/docs/9.3/interactive/tablefunc.html

I do not see how a single "participant count" column will provide a
meaningful piece of data...

David J.






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Not-able-to-understand-how-to-write-group-by-tp5810250p5810279.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


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

Предыдущее
От: Arup Rakshit
Дата:
Сообщение: Re: Not able to understand how to write group by
Следующее
От: Craig Ringer
Дата:
Сообщение: Windows releases - Bundle OpenSSL includes and .libs in the installer?