On 2/21/2014 1:23 PM, David Bicking wrote:
SELECT Key, COUNT(STATUS) Cnt
, MIN(STATUS) || CASE WHEN COUNT(STATUS)>1 THEN '+' ELSE '' END Statuses
FROM T1
WHERE ...
GROUP BY KEY;
Key Cnt Statuses
1 2 O
2 1 C
4 2 O+
The complication is that if a given key has any non-C value, the C values are
to be excluded. If there are only C values, they are to be included.
How can I state the WHERE clause to do that?
You might be looking for something like this:
select key, sum(STATUS != 'C') + (case when sum(STATUS != 'C') = 0 then
sum(STATUS = 'C') else 0 end) Cnt, ...
No special WHERE clause needed.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users