Tuesday, 15 April 2014

sql - conditional select using multiple if conditions -



sql - conditional select using multiple if conditions -

i have rows in table players this.

+-----------+----+----+----+----+----+----+----+----+ | username | | b | c | d | e | f | g | h | +-----------+----+----+----+----+----+----+----+----+ | mike | 45 | 34 | 56 | 58 | 29 | 74 | 39 | 48 | +-----------+----+----+----+----+----+----+----+----+

now query should like..

select username players if (difference between & b <20) if (difference between c & d <20) if (difference between e & f <20) if (difference between g & h <20)

now .. have select username if 2 out of 4 conditions true.. please help

assumed sql server

select username from( select username, case when abs(a-b)<20 1 else 0 end case when abs(c-d)<20 1 else 0 end b case when abs(e-f)<20 1 else 0 end c case when abs(g-h)<20 1 else 0 end d players )tmp tmp.a+tmp.b+tmp.c+tmp.d>=2

sql

No comments:

Post a Comment