Re: SQL query, SELECT (Count/Count ) ...??

From: Brian E Dick <bdick_at_cox.net>
Date: Mon, 17 Mar 2003 02:52:02 GMT
Message-ID: <mLada.52416$Kc5.1743672_at_news2.east.cox.net>


select sum(decode(pv1.idabonne, 'na', 1, 0)) / count(*) from placevendues pv1;

Depending on the Oracle version you could also use CASE instead of DECODE.

"Louis" <louis.gagnon_at_polymtl.ca> wrote in message news:eba8d801.0303141220.55d65544_at_posting.google.com...
> I have a table column containing Registered Users IDs related to
> tickets
> they bought. If the ticket was bought by a non registered user, the
> value 'na'
> is entered.
> Now, I need to find the percentage of the Registered Users that bought
> tickets.
>
> So basically i need to do a divide of the number of Registered users
> by the number of occurence in this column...
>
> here is what i ve been working on:
> (A)
> SELECT COUNT(pv1.idabonne)
> FROM placevendues pv1
> WHERE pv1.idabonne != 'na';
> this counts the number of Registered users who bought tickets (Ex.:let
> s say 30)
>
> (B)
> SELECT COUNT(pv1.idabonne)
> FROM placevendues pv1 ;
> this counts the number of lines in my table (Ex.:let s say 50)
>
> Now.. how can I do some sort of Select A/B*100 so i can have
> the percentage i want...? which would be 30/50*100 = 60%
>
> Thanks
>
> Louis Gagnon
> -Comp. Eng. Student-
Received on Mon Mar 17 2003 - 03:52:02 CET

Original text of this message