I am starting to get a lot of these :
Code:
SELECT `userid`, '' AS `username`, `bets`, `wr`, `rd`, (`bets`-`wr`-`rr`-`rd`) AS `rw`, `rr`,
(`wr`*0)+
(`rr`*3)+
(`rd`*2)+
((`bets`-`wr`-`rr`-`rd`)*1) AS `sum_pts`,
((`wr`/`bets`)*0)+
((`rr`/`bets`)*3)+
((`rd`/`bets`)*2)+
(((`bets`-`wr`-`rr`-`rd`)/`bets`)*1) AS `avg_pts`
FROM
(
SELECT b.`userid`, COUNT(*) AS `bets`,
SUM(`score_key`!=`bet_score_key`) AS `wr`,
SUM(`bet_home`=`points_home` AND `bet_away`=`points_away`) AS `rr`,
SUM(CAST(`bet_home`-`bet_away` AS SIGNED)=(`points_home`-`points_away`)
AND NOT (`bet_home`=`points_home` AND `bet_away`=`points_away`)) AS `rd`
FROM `vb_soccer_user_bet` AS b
INNER JOIN `vb_soccer_match` AS m ON (m.`id`=b.`match_id`)
WHERE `dateline` BETWEEN 1320105600 AND 1322697600 AND `score_key`>0
GROUP BY b.`userid`
) AS `foo`
ORDER BY sum_pts desc , avg_pts desc
LIMIT 0, 30;
MySQL Error : BIGINT UNSIGNED value is out of range in '(`forum`.`b`.`bet_home` - `forum`.`b`.`bet_away`)'