mysql - SQL, Select group by count, on max number of columns -
mysql - SQL, Select group by count, on max number of columns -
we have next sql. grouping product_id , count. limit 6. query , illustration output below.
now, suppose want the group product_id , count. limit 6.
based on last 1000 records in table? not whole table, group/count based on lastly 1000 records. can done?
i using limit grab top 6. there way limit number of columns counted.grouped max?
hope clear
thx, sean
select `t`.`product_id` `id`, count(*) `cnt` `sofreport_viewed_product_index` `t` (t.product_id != '24') , (t.store_id = '1') grouping `t`.`product_id` order `cnt` desc limit 6
id cnt 9 239 440 179 216 169 10 157 494 126 500 118
i think work that,
select `t`.`product_id` `id`, count(*) `cnt` `sofreport_viewed_product_index` `t` (t.product_id != '24') , (t.store_id = '1') , t.product_id in (select id sofreport_viewed_product_index order ‘cnt‘ limit 1000 ) grouping `t`.`product_id` order `cnt` desc limit 6
mysql sql
Comments
Post a Comment