newbie sql question

I working on something that I don't have much experience with. I have the
following query:

select item_no, sum(price), count(*) from production where date >
'2006-11-15' group by item_no;

which returns:

item_no sum(price) count(*)
27714 327.6 6
29582 269.64 4
38599 476.34 6

Is there a way that I can get the total of the sum(price)? Do I need to do
this in PHP?

Thanks for any help that you might be able to provide.

A
Auddog [ Do, 16 November 2006 22:48 ] [ ID #1538000 ]

Re: newbie sql question

Auddog wrote:
> I working on something that I don't have much experience with. I have the
> following query:
>
> select item_no, sum(price), count(*) from production where date >
> '2006-11-15' group by item_no;
>
> which returns:
>
> item_no sum(price) count(*)
> 27714 327.6 6
> 29582 269.64 4
> 38599 476.34 6
>
> Is there a way that I can get the total of the sum(price)? Do I need to do
> this in PHP?
>
> Thanks for any help that you might be able to provide.
>
> A

Can you use subqueries? If so, you can do it this way:

SELECT sum(totals) AS total
FROM (select item_no, sum(price) AS totals, count(*)
from production where date >'2006-11-15' group by item_no)t1;
zac.carey [ Fr, 17 November 2006 09:16 ] [ ID #1539267 ]

Re: newbie sql question

On Nov 17, 3:16 am, "strawberry" <zac.ca... [at] gmail.com> wrote:
> Auddog wrote:
> > I working on something that I don't have much experience with. I have the
> > following query:
>
> > select item_no, sum(price), count(*) from production where date >
> > '2006-11-15' group by item_no;
>
> > which returns:
>
> > item_no sum(price) count(*)
> > 27714 327.6 6
> > 29582 269.64 4
> > 38599 476.34 6
>
> > Is there a way that I can get the total of the sum(price)? Do I need to do
> > this in PHP?
>
> > Thanks for any help that you might be able to provide.
>
> > ACan you use subqueries? If so, you can do it this way:
>
> SELECT sum(totals) AS total
> FROM (select item_no, sum(price) AS totals, count(*)
> from production where date >'2006-11-15' group by item_no)t1;

Or more simply:

SELECT SUM(price)
FROM production
WHERE date > '2006-11-15' ;

?
shakah [ Fr, 17 November 2006 22:59 ] [ ID #1539270 ]
Datenbanken » mailing.database.mysql » newbie sql question

Vorheriges Thema: Foreign key on the same table update problem
Nächstes Thema: Auto Number mysql