3 messages in com.mysql.lists.win32Re: percentages and MySQL
FromSent OnAttachments
webm...@w3space.com13 Oct 2001 08:02 
webm...@w3space.com15 Oct 2001 05:36 
webm...@w3space.com15 Oct 2001 07:06 
Subject:Re: percentages and MySQL
From:webm...@w3space.com (webm@w3space.com)
Date:10/15/2001 05:36:58 AM
List:com.mysql.lists.win32

Hi Robert and thanks

it works (adding a : before the =) but how can I execute a second SELECT query using this variable ?

Here's what I have :

SELECT @tot:=COUNT(*) FROM karikter; SELECT pays, COUNT(pays) AS inscrits, FORMAT(((COUNT(pays)/@tot)*100),2) AS pourcentage FROM karikter GROUP BY pays;

and only the first query is executed !!!

I also tried :

SELECT @tot:=COUNT(*), pays, COUNT(pays) AS inscrits, FORMAT(((COUNT(pays)/@tot)*100),2) AS pourcentage FROM karikter GROUP BY pays;

but it isn't correct, tho it works with no error...

Any more idea ?

-----Message d'origine----- De : Robert Bielecki <robe@hotmail.com> À : webm@w3space.com <webm@w3space.com> Date : lundi 15 octobre 2001 06:03 Objet : Re: percentages and MySQL

Hi,

SELECT @tot:=COUNT(*) FROM karikter ;

Hi MySQL users

I'm trying to produce statistics from people recordings... for instance, i want to have all countries listed with the total of subs for each and a proportion in percentage...

SET @tot=3976; SELECT pays, COUNT(pays) AS inscrits, FORMAT(((COUNT(pays)/@tot)*100),2) AS pourcentage FROM karikter GROUP BY pays;

and get

argentina 6 0.15 australia 60 1.51 austria 1 0.03 etc...

which is fine, BUT :

- is there a way to do something like : SET @tot=("SELECT COUNT(*) FROM karikter") not to have to indicate manually the total number of records ?

- is there a better way of calculating percentages ?

- I also had to format the result when using the @tot variable... If I use instead :

SELECT pays, COUNT(pays) AS inscrits, ((COUNT(pays)/3976)*100) AS pourcentage FROM karikter GROUP BY pays;

then my results are automatically formatted the way I want... Is there a reason for this on using variables ?

Thanks...