0

在工作台上打开一个新会话并尝试运行此查询此查询在第一次执行时返回计数“15”,在第二次执行时返回“4”为什么会这样..

select count(id) 
from (
   select *,@num := if(@company_id = company_id, @num + 1, 1) as row_number,@company_id := company_id as dummy 
   from salebuild_ctl.company_contact 
   where id in (12352,59898,59899,59900,59901,59902,59903,59904,14047,15196,15197,41402,41403,41404,41405)  
   order by company_id,  date_created asc  
) as x 
where x.row_number <= 2; 
4

1 回答 1

1

原因是因为您第一次使用SET @num=0但下次运行查询时您又没有将其设置0为第二次运行它需要@num=15

在第二次运行之前正确运行SET @num=0

于 2013-03-01T07:16:07.190 回答