SQL Server: case case
I have a table named boolean
that contains the values ββ"true" and / or "false" as rows in one column.
I am having a problem creating a statement case
to show me if only values ββare "true" or "false" or "both"
Example 1:
'true'
'true'
result: 'true'
Example 2:
'false'
'false'
'false'
Result: "false"
Example 3:
'true'
'false'
'true'
Result: "both"
Edit:
case
the expression should look like this:
case
when "column content are only true values" then 'true'
when "column content are only false values" then 'false'
else 'both'
end
source to share
You can combine columns in max
and min
in a column and then evaluate the results - if they are the same, there will be only one value in the column. If not, then both should be. Note that since these are string representations, the values ββare sorted lexicographically:
SELECT CASE WHEN MAX(col) = MIN(col) THEN MAX(col) ELSE 'both' END
FROM my_table
source to share