Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
On Thursday, July 03, 2014 11:49:04 AM John R Pierce wrote: > On 7/3/2014 8:24 AM, Arup Rakshit wrote: > >> OT, but it boggles my mind that anyone thinks thats 'better' than the > >> > >> >straight SQL > > > > I would like to see your idea. Could you please ? My thick brain not able > > to produc

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread John R Pierce
On 7/3/2014 8:24 AM, Arup Rakshit wrote: OT, but it boggles my mind that anyone thinks thats 'better' than the >straight SQL I would like to see your idea. Could you please ? My thick brain not able to produce any straight forward one. Not so good in sql recently.. I was referring to the ORM s

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
On Thursday, July 03, 2014 09:04:36 AM John R Pierce wrote: > On 7/3/2014 4:01 AM, Arup Rakshit wrote: > > Exactly.. I am done. Here is the ORM query :- > > OT, but it boggles my mind that anyone thinks thats 'better' than the > straight SQL I would like to see your idea. Could you please ? My t

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
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

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
On Thursday, July 03, 2014 09:04:36 AM John R Pierce wrote: > On 7/3/2014 4:01 AM, Arup Rakshit wrote: > > Exactly.. I am done. Here is the ORM query :- > > OT, but it boggles my mind that anyone thinks thats 'better' than the > straight SQL I would like to see your idea. Could you please ? My t

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread John R Pierce
On 7/3/2014 4:01 AM, Arup Rakshit wrote: Exactly.. I am done. Here is the ORM query :- def self.employee_learning_by_gender(question_id) cpd_id = Measure.find_by(option: 'CPD').id other_id = Measure.find_by(option: 'Others').id User.select("view.gender, sum(view.participant) as par

[GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
Hi, I am working on web development project. There I am using this awesome DB. Let me tell you first the schema that I am having associated the problem. I am having a table *users* - which has many fields. Out of them, the one I need here is *gender*. This column can have value "f"/"m"/"n". I

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
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. Exactly.. I am done. Here is the ORM query :-   def self.employee_learning_by_gender(question_id)     cpd_id =

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Samantha Atkins
unsubscribe pgsql-general@postgresql.org

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread David G Johnston
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_act

Re: [GENERAL] Not able to understand how to write group by

2014-07-03 Thread Arup Rakshit
Are you sure this is what you want? Since there are two columns you will have to either use a CASE or a 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

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Alban Hertroys
On 02 Jul 2014, at 18:55, Arup Rakshit wrote: > Hi, > > I am working on web development project. There I am using this awesome DB. > Let > me tell you first the schema that I am having associated the problem. > > I am having a table *users* - which has many fields. Out of them, the one I > n

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread David G Johnston
afonit wrote >> genderparticipants answer1_avg answer2_avg >> n 3 12 3 >> m 5 4 12 >> f 71523 Are you sure t

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Arup Rakshit
On Wednesday, July 02, 2014 12:28:04 PM David G Johnston wrote: > Steve Crawford wrote > > > Are you sure this is what you want? > > Since there are two columns you will have to either use a CASE or a select > to facilitate calculating the values for each of the columns. > > SELECT gender, ans

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Arup Rakshit
On Wednesday, July 02, 2014 12:28:04 PM David G Johnston wrote: > Steve Crawford wrote > > > Are you sure this is what you want? > > Since there are two columns you will have to either use a CASE or a select > to facilitate calculating the values for each of the columns. > > SELECT gender, ans

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread David G Johnston
Steve Crawford wrote > On 07/02/2014 09:55 AM, Arup Rakshit wrote: >> SELECT users.gender,count(*) as >> participant,avg(daily_action_answers.value) as >> value >> FROM "users" INNER JOIN "daily_action_answers" ON >> "daily_action_answers"."user_id" = "users"."id" >> INNER JOIN "measures" ON "measu

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Steve Crawford
On 07/02/2014 09:55 AM, Arup Rakshit wrote: SELECT users.gender,count(*) as participant,avg(daily_action_answers.value) as value FROM "users" INNER JOIN "daily_action_answers" ON "daily_action_answers"."user_id" = "users"."id" INNER JOIN "measures" ON "measures"."id" = "daily_action_answers"."mea

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Arup Rakshit
On Wednesday, July 02, 2014 02:49:54 PM you wrote: > On Wed, Jul 2, 2014 at 1:44 PM, Arup Rakshit > > wrote: > > *group by* on full table(*users*). I am away from our production DB. Could > > you > > tell me how this little change will solve the whole problem and help me to > > get > > the data a

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread John R Pierce
On 7/2/2014 10:44 AM, Arup Rakshit wrote: *group by* on full table(*users*). I am away from our production DB. Could you tell me how this little change will solve the whole problem and help me to get the data as per the format I am looking for. I believe he meant group by users.gender

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread jared
On Wed, Jul 2, 2014 at 1:44 PM, Arup Rakshit wrote: > > *group by* on full table(*users*). I am away from our production DB. Could > you > tell me how this little change will solve the whole problem and help me to > get > the data as per the format I am looking for. > Arup, I meant: GROUP BY use

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread Arup Rakshit
On Wednesday, July 02, 2014 02:38:36 PM jared wrote: > you have: > GROUP BY users.gender, measures.option > > instead try: > GROUP BY users > > *group by* on full table(*users*). I am away from our production DB. Could you tell me how this little change will solve the whole problem and help me

Re: [GENERAL] Not able to understand how to write group by

2014-07-02 Thread jared
you have: GROUP BY users.gender, measures.option instead try: GROUP BY users On Wed, Jul 2, 2014 at 12:55 PM, Arup Rakshit wrote: > Hi, > > I am working on web development project. There I am using this awesome DB. > Let > me tell you first the schema that I am having associated the problem. >

[GENERAL] Not able to understand how to write group by

2014-07-02 Thread Arup Rakshit
Hi, I am working on web development project. There I am using this awesome DB. Let me tell you first the schema that I am having associated the problem. I am having a table *users* - which has many fields. Out of them, the one I need here is *gender*. This column can have value "f"/"m"/"n". I