Re: Difficult SQL (for me) - please help!
| From: | John W. Holmes | Date: | Sun, 06 Jun 2004 04:39:59 +0000 |
| Subject: | Re: Difficult SQL (for me) - please help! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187722@lists.php.net to get a copy of this message | ||
Brian Dunning wrote:
Thanks to all who helped with my earlier SQL question. It was exactly what I needed. But now I'm making it more involved. Tom and Dick are competing salesmen. The data looks like this: Tom Pitch Dick Pitch Tom Sale Dick Sale Tom Pitch I want to show a list of salesmen, sorted by rate of sales: Dick 1 sale in 2 tries, 50.0%SELECT name, SUM(IF(result='Pitch',1,0)) as Tot_Pitches, SUM(IF(result='Sale',1,0)) as Tot_Sales, COUNT(result) AS cnt FROM yourtable GROUP BY name -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.comTom 1 sale in 3 tries, 33.3%Is this possible with a single SQL statement? Many thanks,