newbie sql question

newbie sql question

am 16.11.2006 22:48:38 von Auddog

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

Re: newbie sql question

am 17.11.2006 09:16:26 von zac.carey

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;

Re: newbie sql question

am 17.11.2006 22:59:45 von shakah

On Nov 17, 3:16 am, "strawberry" 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' ;

?