sql server - SQL Grouping with a logic check on another column? -
lets have following table:
id param result 1 aaa true 1 aaa false 1 aaa false 1 bbb true 1 ccc true 2 aaa true 2 ccc true 3 aaa false 3 aaa false 3 aaa false 3 ccc true 3 bbb true
is there way group [param] column [result] show true if of corresponding results true , show false if none true? below example of aiming for:
id param result 1 aaa true 1 bbb true 1 ccc true 2 aaa true 2 ccc true 3 aaa false 3 ccc true 3 bbb true
here sketch of code work. need put in right constants result
:
select id, param, (case when sum(case when result = true 1 else 0 end) > 0 true else false end) table t group id, param;
sql server not have native boolean type , doesn't understand "true" , "false". representations (such 'true'
, 'false'
), following work:
select id, param, max(result) result table t group id, param;
Comments
Post a Comment