hi rus,
It seems my first question was not very clear. I wanted to use a function
that I don't know if it exists or if there is some way to do this. Its name
is TOTAL and what it does is add all values ignoring the GROUP BY clause,
unlike SUM that is affected by GROUP BY.
So from a bigger table than what I had below:
Event_Num, Name, Amount
1 Name1 15
2 Name2 15
3 Name3 30
4 Name1 45
5 Name2 20
6 Name3 35
I can get the following output:
Name, Amount, Total, Percent
Name1 60 160 37.5
Name2 35 160 21.875
Name3 65 160 40.625
So if the function TOTAL exists, I can do this:
SELECT Name, sum(Amount) as Amount, TOTAL(Amount) as Total, 100 *
Amount/Total as Percent from table1 where ... GROUP BY Name;
and TOTAL would give me the TOTAL of all Amounts so I can use it to
calculate for percent.
I want can do this calculation in one line. :) Currently I use two SELECT
statements, the first to get the total, then use that value to calculate for
the percent.
jerome
From: "Rus" <[EMAIL PROTECTED]>
To: "jerome auza" <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
Subject: Re: Help please: getting the total from the results of SUM
Date: Thu, 15 Feb 2001 00:47:49 +0300
Did you try
select count(*), sum(amount) from table1;
you also can use
... count(if(field=value,1,NULL)) ...
----- Original Message -----
From: jerome auza <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 14, 2001 2:49 AM
Subject: Help please: getting the total from the results of SUM
> Hi,
>
> Is it possible to get the total from the results of SUM in the same SQL
> statement?
>
> I want to have this output:
>
> Name Amount Percent
> Name1 15 25
> Name2 15 25
> Name3 30 50
>
> My database only have the first two columns and the Percent column is
> calculated as 100 * Amount/TOTAL where TOTAL is equal to the SUM of the
> Amounts. Note that TOTAL would change if I have a different WHERE
clause.
>
> Any help would be appreciated.
>
> jerome
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php