You can do in SQL by using UNION and subselect, something similar to this
(not tested):

select a1, count(a1) from (SELECT c1 FROM t1 UNION SELECT c2 FROM t1 UNION
SELECT c2 FROM t1) as a1 GROUP BY a1;



2013/8/28 davedigerati <hypr...@gmail.com>

> humbly bumping...
>
> On Sunday, August 25, 2013 1:32:35 PM UTC-4, davedigerati wrote:
>>
>> Is there a way to SELECT from my (SQLite) db with example structure/data
>> that looks like this:
>>
>> sue | dog | cat | dog
>> joe | cat | rat | dog
>> joe | dog | dog | rat
>> joe | cat | cat | cat
>> tom | rat | dog | dog
>>
>> a counted, grouped-by set for JOE only that looks like:
>> cat - 4
>> dog - 3
>> rat - 2
>>
>> I've been playing with selecting Joe's records, then looping over them
>> building subtotals in a dict, but this seems a huge waste of effort and my
>> data is actually much larger so I am worried about performance as I try to
>> scale this.  From what I read the groupby is for by fields only, not by
>> counted values?  Can anyone point me in the right direction? thanks!
>>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to