我想计算win_loose字段中的胜出次数,直到达到“松散”,然后停止计数并显示该数字。我有这个,但它算上所有胜利。
$item_count = "SELECT SUM(if(win_loose='win',1,0)) AS user_wins FROM weekpicks";
$item_result = @mysql_query($item_count) or die(mysql_error());
$playerwins = @mysql_result($item_result,0,"user_wins");
echo "$playerwins";
答案 0 :(得分:0)
我现在无法测试,但认为使用变量可能是一个很好的方法
SELECT SUM(@n := if(@n and (win_loose='win'),1,0)) AS user_wins
FROM weekpicks
cross join
(select @n := 1) n