Ballin!
---
Jason Soo
"I'm going to live forever or die trying."

On Fri, Jan 8, 2010 at 4:48 PM, Rob Biedenharn
<r...@agileconsultingllc.com>wrote:

> On Jan 8, 2010, at 5:30 PM, Karl Smith wrote:
>
>  Can someone give me a hand with the sql (mysql works for me) for this
>> rails project...
>>
>> Data similar to this:
>>
>> Station Status
>> WKRP            Pending
>> WKRP            Pending
>> WKRP            Deleted
>> WIBC            Deleted
>> WFBQ            Pending
>> WFBQ            Nutty
>>
>> What I need is an sql statement that will count the various status
>> states and return a *single row* for each station. Like:
>>
>> Station Pending Deleted Nutty
>> WKRP            2               1               0
>> WIBC            0               1               0
>> WFBQ            1               0               1
>>
>> I can get the counts of each station/status in individual lines and
>> loop through the array counting the various status states, but the
>> runtime for that is growing and I'm looking for a better solution
>> before it becomes a problem.
>>
>>
>> Ideas or suggestions?
>> --
>>
>
>
> 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<rubyonrails-talk%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
>
>
--
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