On Jan 8, 2010, at 9:04 PM, Karl Smith wrote:

Thanks Rob, that's pretty good. Close to one of my attempts.

But what if status is not static? The distinct values of `status`
change in value and quantity... which it does.

Then you can build the SQL after first getting the distinct values of the status.

Or do the analysis in ruby after getting the raw [station, status] data.

-Rob



On Jan 8, 3:48 pm, Rob Biedenharn <r...@agileconsultingllc.com> wrote:

SELECT station,
        SUM(CASE WHEN status = 'Pending' THEN 1 ELSE 0 END) AS
"Pending",
        SUM(CASE WHEN status = 'Deleted' THEN 1 ELSE 0 END) AS
"Deleted",
SUM(CASE WHEN status = 'Nutty' THEN 1 ELSE 0 END) AS "Nutty"
FROM your_table
GROUP BY station;

How does that work for you?

-Rob

Rob Biedenharn          http://agileconsultingllc.com
r...@agileconsultingllc.com
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .



Rob Biedenharn          http://agileconsultingllc.com
r...@agileconsultingllc.com



-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to