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]
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]
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
And I have a table like this click send on accident? A Don't leave me hangin'!! -- Tripp --- Claire Lee <[EMAIL PROTECTED]> wrote: > I have a table like this > > name price type > A > > > > __ > Do you Yahoo!? > New and Improved Yahoo! Mail - Send 10MB messages! > http://promotions.yahoo.com/new_mail > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/[EMAIL PROTECTED] > > __ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
distinct based on two fields
I have a table like this name price type A __ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]