Sum() is driven by the group by.

I need it to be equivalent to this:
Select company, state, sales, sales / (select sum(sales) from sales) as
percent from sales

Which of course I could just use that, but the select I'm actually working
with isn't that simple and if there was some way to do what I asked below,
that would be much easier.

I've gathered that is really the only option when it comes down to it so I'm
working on writing my select using the above syntax.

Thanks all!

Thanks,

David Ruggles
CCNA MCSE (NT) CNA A+
Network Engineer        Safe Data, Inc.
(910) 285-7200  [EMAIL PROTECTED]



-----Original Message-----
From: Ian Simpson [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 25, 2008 11:15 AM
To: David Ruggles
Cc: 'mysql'
Subject: RE: How do I (can I) use aggregate functions inside a select


Hi David,

Try

Select company, state, sales, sum(sales) / sales as percent
>From Sales GROUP BY company, state;

Not sure if you always want to group by state; if each company exists in
only one state then the group by is irrelevant, if not then it will give
you the by-state breakdown.



On Fri, 2008-07-25 at 10:53 -0400, David Ruggles wrote:
> I get:
> Error Code : 1140
> Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
> illegal if there is no GROUP BY clause
> 
> Thanks,
> 
> David Ruggles
> CCNA MCSE (NT) CNA A+
> Network Engineer      Safe Data, Inc.
> (910) 285-7200        [EMAIL PROTECTED]
> 
> 
> 
> -----Original Message-----
> From: Ananda Kumar [mailto:[EMAIL PROTECTED] 
> Sent: Friday, July 25, 2008 10:37 AM
> To: David Ruggles
> Cc: mysql
> Subject: Re: How do I (can I) use aggregate functions inside a select
> 
> 
> yes, u can use the below sql.
> 
> regards
> anandkl
> 
> 
> On 7/25/08, David Ruggles <[EMAIL PROTECTED]> wrote:
> >
> > I may be approaching this all wrong, but I need to know a percentage of
> > total sales within a select statement.
> >
> > So I can do something like this:
> > Select company, state, sales, sum(sales) / sales as percent
> > From Sales
> >
> >
> > Thanks,
> >
> > David Ruggles
> > CCNA MCSE (NT) CNA A+
> > Network Engineer        Safe Data, Inc.
> > (910) 285-7200  [EMAIL PROTECTED]
> >
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> >
> >
> 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: 7/25/2008
> 6:51 AM
> 
> 
> 
-- 
Ian Simpson
System Administrator
MyJobGroup

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: 7/25/2008
6:51 AM



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to