>From: David Ruggles [mailto:david@stripped]
>Sent: Friday, July 25, 2008 10:53 AM
>Subject: RE: How do I (can I) use aggregate functions inside a select
>Error Code : 1140
>Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns
>illegal if there is no GROUP BY clause
[JS] I think you can do what you want with a little bit of modification, but
I'm not sure exactly what you want. If what you want is to have the sales %
for each company, for example, you could use
SELECT MIN(company) AS comp, MIN(state) AS st, SUM(sales) AS comp_tot,
SUM(sales) * 100 / (SELECT SUM(sales) FROM sales_table)) AS pct_sales
FROM sales_table GROUP BY company, state;
I tested a simplified case, but I believe this will work. The use of the MIN
function is because you need a group function, and because the MIN and MAX
of company is the same through the entire group it works just fine.
>CCNA MCSE (NT) CNA A+
>Network Engineer Safe Data, Inc.
>(910) 285-7200 david@stripped
>From: Ananda Kumar [mailto:anandkl@stripped]
>Sent: Friday, July 25, 2008 10:37 AM
>To: David Ruggles
>Subject: Re: How do I (can I) use aggregate functions inside a select
>yes, u can use the below sql.
>On 7/25/08, David Ruggles <david@stripped> wrote:
>> I may be approaching this all wrong, but I need to know a percentage
>> total sales within a select statement.
>> So I can do something like this:
>> Select company, state, sales, sum(sales) / sales as percent
>> From Sales
>> David Ruggles
>> CCNA MCSE (NT) CNA A+
>> Network Engineer Safe Data, Inc.
>> (910) 285-7200 david@stripped
>> MySQL General Mailing List
>> For list archives: http://lists.mysql.com/mysql
>> To unsubscribe:
>No virus found in this incoming message.
>Checked by AVG - http://www.avg.com
>Version: 8.0.138 / Virus Database: 270.5.6/1572 - Release Date:
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=1