为什么在MySQL中使用Having子句时会跳过序列号

时间:2016-08-05 07:14:33

标签: mysql

我的查询:

    Select 
        @a:=@a+1 serial_number,
        CONCAT_WS(' ',ap.FirstName,ap.LastName) as Name,
        Count(t.ID) as NoOfBookings
    from 
        tablereservation t, 
        appusers ap , 
        (SELECT @a:= 0) AS a 
    where 
        t.AppUserID = ap.ID 
        AND
        t.RestaurantID = p_RestaurantID 
    GROUP BY CONCAT_WS(' ',ap.FirstName,ap.LastName) 
    HAVING Count(t.ID)=1
    Order by serial_number; 

结果:

enter image description here

我希望序列号从1开始,但是从5开始。

TableReservation表:

enter image description here

用户表:

enter image description here

0 个答案:

没有答案