Re: Not able to understand how to write group by - Mailing list pgsql-general

From David G Johnston
Subject Re: Not able to understand how to write group by
Date
Msg-id 1404375278325-5810365.post@n5.nabble.com
Whole thread Raw
In response to Re: Not able to understand how to write group by  (Arup Rakshit <aruprakshit@rocketmail.com>)
Responses Re: Not able to understand how to write group by  (Arup Rakshit <aruprakshit@rocketmail.com>)
List pgsql-general
Arup Rakshit wrote
> SELECT users.gender,count(*) as participant,
> case when daily_action_answers.measure_id = 1 then
> avg(daily_action_answers.value) end as cpd,
> case when daily_action_answers.measure_id = 2 then
> avg(daily_action_answers.value) end as other 
> FROM users INNER JOIN daily_action_answers ON daily_action_answers.user_id
> = users.id
> INNER JOIN measures ON measures.id = daily_action_answers.measure_id
> WHERE (((daily_action_answers.day between '2014-07-03' and
> '2014-12-31')and daily_action_answers.daily_action_id = 1)) 
> GROUP BY users.gender, daily_action_answers.measure_id
>
> gender | participant | cpd |other 
>
> "Female", 2 , 8.5, 0.0
> "Female", 1 , 0.0, 8.0
> "None", 2, 6.5, 0.0
> "None", 1, 0.0, 5.0
> "Male", 1, 4.0, 0.0, 
> "Male", 2, 0.0, 10.0
>
> Problem is.. I am not able to merge those pair rows into one... :-(

Without commenting on the rest of it...to combine what you show here just
GROUP BY gender and SUM() everything else (i.e., turn the above into a
subquery and then do this)

David J.




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


pgsql-general by date:

Previous
From: Dave Page
Date:
Subject: Re: Windows releases - Bundle OpenSSL includes and .libs in the installer?
Next
From: Jacob Bunk Nielsen
Date:
Subject: Re: Next steps in debugging database storage problems?