i have a table with five column
ID INT, Reading1 INT, Reading2 INT, Status1 INT, Status2 INT
I want to select reading1 if reading1 value is greater than reading2 value and want to select status1 value with it. If reading2 value is greater than reading1 value then I want to select reading2 value and status2 value.
I have tried but it gives me an error:
select ID,
case when reading1 > reading2 then reading1 when reading2 > reading1 then reading2 as readings,
case when reading1 > reading2 then status1 when reading2 > reading1 then status2 as status
from table
my table's data
ID Reading1 Reading2 Status1 Status2
1 113 88 1 0
2 176 22 2 -1
3 204 39 3 -1
4 99 107 0 1
5 86 103 0 1
6 78 101 0 1
7 100 53 1 0