Query including "SET @xxx; @xxx:= @xxx+1" got wrong result set

15 views
Skip to first unread message

PeiJie Lin

unread,
Jan 6, 2016, 3:09:40 PM1/6/16
to redbeanphp
Have someone meet this? 

RedBeanPHP give different result set from native PDO result set when using SQL this, (to get top 5)

     SELECT CASE WHEN @cn = a.cn THEN @rank := @rank + 1 ELSE @rank := 1 END  AS v1,
                   @cn := a.cn                                                                                                AS v2,
                   CASE WHEN @rank <= 4 THEN cust_name ELSE "other" END                     AS v3,
                   SUM(ct)                                                                                                      AS v4
         FROM xxx a
 CROSS JOIN (SELECT @cn := NULL, @rank := 0 ) b 
     GROUP BY v2, v3
     ORDER BY v2, v1 ',

RedBean result by getAll has rows whose rank(v1) > 5, but native PDO returns rows with only rand <=5
Reply all
Reply to author
Forward
0 new messages