sql - transform and group data together -
from query retrieve information need results this:
code | category ----------- 1 | 1 | 2 | b 3 | b 3 | b 4 | b
from data following result:
combination 1&2 | combination 3&4 --------------------------------- 'both & b' | 'just b"
so happening is, if first column takes rows code 1 or 2. sees if in these rows:
-are rows equal category result in value "just a"
-are rows equal category b result in value"just b"
-is there mix of categories , b's codes 1 , 2 result in value"both & b".
this again happen inside of second column except codes 3&4. in practice combining many codes of these column, columns combine 2 codes, other can combine 10 codes, , on. trying see category combination of codes are. a's, b's, or @ mixed?
you can use conditional aggregation:
select (case when min(category) <> max(category) 'both , b' when min(category) = 'a' 'a only' when min(category) = 'b' 'b only' end) t code in (1, 2) , category in ('a', 'b');