distinct based on two fields--please help
I have a table like this name price type A10 1 B30 2 A20 1 B20 2 would like to distinct based on name and type, do a sum and get the following result name price type A 30 1 B 50 2 How do I do this with one sql query? Thanks. Claire ___ Do you Yahoo!? Express yourself with Y! Messenger! Free. Download now. http://messenger.yahoo.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: distinct based on two fields--please help
From: Claire Lee [mailto:[EMAIL PROTECTED] I have a table like this name price type A10 1 B30 2 A20 1 B20 2 would like to distinct based on name and type, do a sum and get the following result name price type A 30 1 B 50 2 How do I do this with one sql query? Thanks. SELECT name, SUM(price), type FROM tablename GROUP BY name, type; -- Mike Johnson Web Developer Smarter Living, Inc. phone (617) 886-5539 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: distinct based on two fields--please help
- Original Message - From: Claire Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, August 03, 2004 11:28 AM Subject: distinct based on two fields--please help I have a table like this name price type A10 1 B30 2 A20 1 B20 2 would like to distinct based on name and type, do a sum and get the following result name price type A 30 1 B 50 2 How do I do this with one sql query? Thanks. You don't need (or want) distinct in this case. select name, type, sum(price) from mytable group by name, type This will lump together all rows that have the same name/type combination and then sum the prices of those rows. The result will be exactly what you requested: a single row for each name/type combination showing the total for that combination. Rhino -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]