谁能解释以下两个请求之间的区别:
SET @foundnow=0;
SELECT id, (@foundnow:=IF(`id`=3,1,0)) as ff
FROM `sometable`
HAVING @foundnow=0
result is
id ff
1 0
2 0
3 1
和
SET @foundnow=0;
SELECT id, (@foundnow:=IF(`id`=3,1,0)) as ff
FROM `sometable`
HAVING ff=0
result is
id ff
1 0
2 0
4 0
5 0
...
为什么首先给出id = 3(包括)的所有行,第二个 - 除了id = 3的所有行?
我想与这个问题相关的是以下请求的“意外”行为
SET @tot=0;
SELECT @tot:=@tot+1 as `ff`
FROM `anytable`
HAVING (`ff`>10)
给出 ff=12,14,16,18 的行...