pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPercentage of Total Occurances
5+ messages / 2 participants
[nested] [flat]
* Percentage of Total Occurances
@ 2003-04-15 14:53 Adam Sherman <adam@tritus.ca>
0 siblings, 1 reply; 5+ messages in thread
From: Adam Sherman @ 2003-04-15 14:53 UTC (permalink / raw)
To: pgsql-sql
I have a table being used for poll results:
id
poll_id
question_id
answer_id
datestamp
I what to figure out the percentage or respondants that gave each answer.
This is based on occurance rather than values.
I want to be able to figure it out for a single (poll_id,qustion_id)
combination and also for multiple questions.
Thanks for your help,
A.
--
Adam Sherman
Tritus CG Inc.
http://www.tritus.ca/
+1 (613) 797-6819
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Percentage of Total Occurances
@ 2003-04-15 17:10 mallah@trade-india.com
parent: Adam Sherman <adam@tritus.ca>
0 siblings, 1 reply; 5+ messages in thread
From: mallah@trade-india.com @ 2003-04-15 17:10 UTC (permalink / raw)
To: adam@tritus.ca; +Cc: pgsql-sql
> I have a table being used for poll results:
>
> id
> poll_id
> question_id
> answer_id
> datestamp
>
> I what to figure out the percentage or respondants that gave each answer. This is based on
> occurance rather than values.
select answer_id,count(*) from polls where poll_id = ?
group by answer_id ;
gives number of response of each answer
total_response = select count(*) from polls where poll_id = ?
getting %age shud be trivial.
Dunno if i missed your question .
>
> I want to be able to figure it out for a single (poll_id,qustion_id) combination and also for
> multiple questions.
>
sorry i do not get it.
> Thanks for your help,
>
> A.
>
>
> --
> Adam Sherman
> Tritus CG Inc.
> http://www.tritus.ca/
> +1 (613) 797-6819
>
>
> ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9'
> the postmaster
-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Percentage of Total Occurances
@ 2003-04-15 18:59 Adam Sherman <adam@tritus.ca>
parent: mallah@trade-india.com
0 siblings, 1 reply; 5+ messages in thread
From: Adam Sherman @ 2003-04-15 18:59 UTC (permalink / raw)
To: ; +Cc: pgsql-sql
On 04/15/03 22:40:37 +0530 mallah@trade-india.com wrote:
>> I have a table being used for poll results:
>>
>> id
>> poll_id
>> question_id
>> answer_id
>> datestamp
>>
>> I what to figure out the percentage or respondants that gave each
>> answer. This is based on occurance rather than values.
>
> select answer_id,count(*) from polls where poll_id = ?
> group by answer_id ;
>
> gives number of response of each answer
>
> total_response = select count(*) from polls where poll_id = ?
>
> getting %age shud be trivial.
>
> Dunno if i missed your question .
I'm looking to do everything in a single query.
And get something like:
answer_id -> percentage
Thanks,
A.
--
Adam Sherman
Tritus CG Inc.
http://www.tritus.ca/
+1 (613) 797-6819
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Percentage of Total Occurances
@ 2003-04-15 19:41 mallah@trade-india.com
parent: Adam Sherman <adam@tritus.ca>
0 siblings, 1 reply; 5+ messages in thread
From: mallah@trade-india.com @ 2003-04-15 19:41 UTC (permalink / raw)
To: adam@tritus.ca; +Cc: pgsql-sql
well if everything in a single query is that imp u may do this subselect:
select answer_id , 1.0*count(*) / (select count(*) from polls where poll_id = ?)
from polls where poll_id = ? group by answer_id ;
and if u need to trim the trailing digits after decimal
do to_char(value , '99.99')
since u have not provided any sample data i cann't test it.
> On 04/15/03 22:40:37 +0530 mallah@trade-india.com wrote:
>
>>> I have a table being used for poll results:
>>>
>>> id
>>> poll_id
>>> question_id
>>> answer_id
>>> datestamp
>>>
>>> I what to figure out the percentage or respondants that gave each answer. This is based on
>>> occurance rather than values.
>>
>>
select answer_id , 1.0*count(*) / (select count(*) from polls where poll_id = ?)
from polls where poll_id = ? group by answer_id ;
>>
>> gives number of response of each answer
>>
>> total_response = select count(*) from polls where poll_id = ?
>>
>> getting %age shud be trivial.
>>
>> Dunno if i missed your question .
>
> I'm looking to do everything in a single query.
>
> And get something like:
>
> answer_id -> percentage
>
> Thanks,
>
> A.
>
> --
> Adam Sherman
> Tritus CG Inc.
> http://www.tritus.ca/
> +1 (613) 797-6819
>
>
> ---------------------------(end of broadcast)--------------------------- TIP 5: Have you
> checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Percentage of Total Occurances
@ 2003-04-16 04:38 Adam Sherman <adam@tritus.ca>
parent: mallah@trade-india.com
0 siblings, 0 replies; 5+ messages in thread
From: Adam Sherman @ 2003-04-16 04:38 UTC (permalink / raw)
To: pgsql-sql; +Cc: mallah@trade-india.com
On 04/16/03 01:11:08 +0530 mallah@trade-india.com wrote:
>
>
> well if everything in a single query is that imp u may do this subselect:
>
> select answer_id , 1.0*count(*) / (select count(*) from polls where
> poll_id = ?) from polls where poll_id = ? group by answer_id ;
>
> and if u need to trim the trailing digits after decimal
> do to_char(value , '99.99')
>
> since u have not provided any sample data i cann't test it.
Thanks for your help, this was simpler than I thought.
A.
--
Adam Sherman
Tritus CG Inc.
http://www.tritus.ca/
+1 (613) 797-6819
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-04-16 04:38 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-15 14:53 Percentage of Total Occurances Adam Sherman <adam@tritus.ca>
2003-04-15 17:10 ` mallah@trade-india.com
2003-04-15 18:59 ` Adam Sherman <adam@tritus.ca>
2003-04-15 19:41 ` mallah@trade-india.com
2003-04-16 04:38 ` Adam Sherman <adam@tritus.ca>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox