Discussion:
need help constructing a query
(too old to reply)
m***@googlemail.com
2007-02-16 08:58:15 UTC
Permalink
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
strawberry
2007-02-16 10:21:19 UTC
Permalink
Post by m***@googlemail.com
hi
product id | product name | product price
the product name and product price fields both contain duplicate
values
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.
socks | 47
shoes | 18
can anyone help with this?
thanks
marc
look at SUM and GROUP BY in the manual
m***@googlemail.com
2007-02-16 11:15:17 UTC
Permalink
Post by strawberry
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.
t***@yahoo.com
2007-02-16 15:31:04 UTC
Permalink
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.
Post by m***@googlemail.com
Post by strawberry
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.
s***@gmail.com
2007-02-17 16:20:44 UTC
Permalink
Post by t***@yahoo.com
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.
Post by m***@googlemail.com
Post by strawberry
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 ;

Loading...