sql - How to select certain numbers of groups in MySQL? -
i have table data: , table need create pegination productid column. know limit n,m, works rows , not groups. examle table pegination = 2 expect retrieve 9 records productid = 1 , 2 (the number of groups 2).
so how create pegination numbers of groups ?
i thankfull answers example.
one way pagination groups assign product sequence query. using variables, requires subquery:
select t.* (select t.*, (@rn := if(@p = productid, @rn + 1, if(@rn := productid, 1, 1) ) ) rn table t cross join (select @rn := 0, @p := -1) vars order t.productid ) t rn between x , y;
with index on t(productid)
, can subquery. condition can go in having
clause:
select t.*, (select count(distinct productid) t t2 t2.productid <= t.productid) ) pno t having pno between x , y;
Comments
Post a Comment