Page 1 of 1

selecting unique records

Posted: Wed Sep 14, 2005 12:21 am
by michlcamp
I've got a database table named 'sales' where each sale has these fields:

id, item,price,salesperson

table looks like:

1 item1 2.00 bob
2 item2 3.00 bob
3 item3 4.00 bob

I want to display:

Code: Select all

---------------------
|salesperson | total |
---------------------
| bob       | 9.00 |
----------------------
how do I write the query?

Any help appreciated..
thanks.
mc

Posted: Wed Sep 14, 2005 12:59 am
by feyd

Code: Select all

SELECT  `salesperson`, SUM(`price`) AS `total` FROM `salesperson` GROUP BY `salesperson`


moved to Databases.

Posted: Wed Sep 14, 2005 2:49 am
by itsmani1
feyd wrote:

Code: Select all

SELECT  `salesperson`, SUM(`price`) AS `total` FROM `salesperson` GROUP BY `salesperson`
moved to Databases.
[GROUP BY] => what will it do ?

Posted: Wed Sep 14, 2005 7:14 am
by michlcamp
Thanks much. works great.

Posted: Wed Sep 14, 2005 11:22 am
by feyd
itsmani1 wrote:[GROUP BY] => what will it do ?
The manual has all the info you need: http://dev.mysql.com/doc/mysql/en/select.html