Q: conditional select using multiple if conditions I have rows in a table Players like this.
+-----------+----+----+----+----+----+----+----+----+
|  USERNAME | A  | B  | C  | D  | E  | F  | G  | H  |
+-----------+----+----+----+----+----+----+----+----+
|   Mike    | 45 | 34 | 56 | 58 | 29 | 74 | 39 | 48 |
+-----------+----+----+----+----+----+----+----+----+

Now My Query should BE SOMETHING LIKE..

SELECT USERNAME FROM PLAYERS 
IF 
 (DIFFERENCE BETWEEN A & B <20)

IF
 (DIFFERENCE BETWEEN C & D <20)

IF
 (DIFFERENCE BETWEEN E & F <20)
IF
 (DIFFERENCE BETWEEN G & H <20)


Now .. I have to select username if any two out of four conditions are true..
Please help

A: Assumed SQL Server
select
   username 
from(
    SELECT USERNAME,
        case when abs(a-b)<20 then 1 else 0 end A
        case when abs(c-d)<20 then 1 else 0 end b
        case when abs(e-f)<20 then 1 else 0 end c
        case when abs(g-h)<20 then 1 else 0 end d
    FROM PLAYERS
)tmp
WHERE tmp.a+tmp.b+tmp.c+tmp.d>=2


A: Assuming mysql:
select username from (
    select username,
        if(b-a < 20, 1, 0) as ab,
        if(d-c < 20, 1, 0) as cd,
        if(f-e < 20, 1, 0) as ef,
        if(h-g < 20, 1, 0) as gh
    from players
) x where ab + cd + ef + gh = 2

You may want to use abs() if a can be higher than b.  You may want to use >= 2 if two or more conditions are fine.
