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%
  Tom    1 sale in 3 tries, 33.3%

Is this possible with a single SQL statement? Many thanks,

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.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to