need help constructing a query

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
mcyi2mr3 [ Fr, 16 Februar 2007 09:58 ] [ ID #1631141 ]

Re: need help constructing a query

On Feb 16, 8:58 am, "mcyi2... [at] googlemail.com"
<mcyi2... [at] 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
zac.carey [ Fr, 16 Februar 2007 11:21 ] [ ID #1631142 ]

Re: need help constructing a query

> 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.
mcyi2mr3 [ Fr, 16 Februar 2007 12:15 ] [ ID #1631144 ]

Re: need help constructing a query

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... [at] googlemail.com"
<mcyi2... [at] 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.
torpecool [ Fr, 16 Februar 2007 16:31 ] [ ID #1631145 ]

Re: need help constructing a query

On Feb 16, 10:31 am, torpec... [at] 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... [at] googlemail.com"
>
> <mcyi2... [at] 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 ;
shakah [ Sa, 17 Februar 2007 17:20 ] [ ID #1632281 ]
Datenbanken » mailing.database.mysql » need help constructing a query

Vorheriges Thema: the use of "in"
Nächstes Thema: show numbers of records as % ???