Re: Percentage of Total Occurances

Поиск
Список
Период
Сортировка
От
Тема Re: Percentage of Total Occurances
Дата
Msg-id 1608.219.65.253.230.1050435668.squirrel@mail.trade-india.com
обсуждение исходный текст
Ответ на Re: Percentage of Total Occurances  (Adam Sherman <adam@tritus.ca>)
Ответы Re: Percentage of Total Occurances  (Adam Sherman <adam@tritus.ca>)
Список 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 = ?
groupby 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/



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

Предыдущее
От: Fernando Eduardo Carvalho
Дата:
Сообщение: plpgsql slow in 7.3 ????
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: SELECT INTO TEMP in Trigger?