need help constructing a query
need help constructing a query
am 16.02.2007 09:58:15 von mcyi2mr3
hi
i have a table like this:
product id | product name | product price
the product name and product price fields both contain duplicate
values
for example:
1 | socks | 23
3 | shoes | 18
2 | socks | 24
what i need to do is work out the total of the price field for each
value of the name field.
so a list can be displayed like:
socks | 47
shoes | 18
can anyone help with this?
thanks
marc
Re: need help constructing a query
am 16.02.2007 11:21:19 von zac.carey
On Feb 16, 8:58 am, "mcyi2...@googlemail.com"
wrote:
> hi
>
> i have a table like this:
>
> product id | product name | product price
>
> the product name and product price fields both contain duplicate
> values
>
> for example:
>
> 1 | socks | 23
> 3 | shoes | 18
> 2 | socks | 24
>
> what i need to do is work out the total of the price field for each
> value of the name field.
>
> so a list can be displayed like:
>
> socks | 47
> shoes | 18
>
> can anyone help with this?
>
> thanks
>
> marc
look at SUM and GROUP BY in the manual
Re: need help constructing a query
am 16.02.2007 12:15:17 von mcyi2mr3
> look at SUM and GROUP BY in the manual
Thanks. What would be really helpful would be if someone could
actually show me an example of this using the example I gave in my
original post.
Re: need help constructing a query
am 16.02.2007 16:31:04 von torpecool
I didn't test this, but give it a try. I think this should be close
to what you are looking for.
SELECT SUM(product price)
FROM your_table
GROUP BY product name
Just a guess... hope it helps.
On Feb 16, 6:15 am, "mcyi2...@googlemail.com"
wrote:
> > look at SUM and GROUP BY in the manual
>
> Thanks. What would be really helpful would be if someone could
> actually show me an example of this using the example I gave in my
> original post.
Re: need help constructing a query
am 17.02.2007 17:20:44 von shakah
On Feb 16, 10:31 am, torpec...@yahoo.com wrote:
> I didn't test this, but give it a try. I think this should be close
> to what you are looking for.
>
> SELECT SUM(product price)
> FROM your_table
> GROUP BY product name
>
> Just a guess... hope it helps.
>
> On Feb 16, 6:15 am, "mcyi2...@googlemail.com"
>
> wrote:
> > > look at SUM and GROUP BY in the manual
>
> > Thanks. What would be really helpful would be if someone could
> > actually show me an example of this using the example I gave in my
> > original post.
The following might be more useful:
SELECT product_name, SUM(product_price)
FROM your_table
GROUP BY product_name ;