ClanCats / Hydrahon

🐉 Fast & standalone PHP MySQL Query Builder library.
https://clancats.io/hydrahon/master/
MIT License
278 stars 58 forks source link

SUM with IF #36

Open reklin7jc opened 4 years ago

reklin7jc commented 4 years ago

how would this consultation with the hydrahon be?

SUM(+1) as matches, SUM(IF((matches.playerblue = '.$idPlayer.' AND matches.rtb > matches.rtr) OR (matches.playerred = '.$idPlayer.' AND matches.rtr > matches.rtb), 1, 0)) as victories, SUM(IF((matches.playerblue = '.$idPlayer.' AND matches.rtb < matches.rtr) OR (matches.playerred = '.$idPlayer.' AND matches.rtr < matches.rtb), 1, 0)) as defeats, SUM(IF((matches.playerblue = '.$idPlayer.' AND matches.rtb = matches.rtr) OR (matches.playerred = '.$idPlayer.' AND matches.rtr = matches.rtb), 1, 0)) as drowns, SUM(IF(matches.playerblue = '.$idPlayer.', matches.rtb, 0) + IF(matches.playerred = '.$idPlayer.' , matches.rtr, 0)) as goalscored, SUM(IF(matches.playerblue = '.$idPlayer.', matches.rtr, 0) + IF(matches.playerred = '.$idPlayer.' , matches.rtb, 0)) as concededgoals, WHERE matches.playerblue = '.$idPlayer.' OR matches.playerred = '.$idPlayer.' LIMIT '.$games