php - How to get rank according to count in mysql -
i getting issue fetching rank according count.
i have 2 tables :
1)images 2)images_like
now if images_like have no entries showing "null" in ranks. please check query , output :
select im.id, rank (select image_id, @rownum := @rownum + 1 rank, count(*) cnt images_like, (select @rownum := 0) r group image_id order `cnt` desc) d right join images im on d.image_id = im.id
i need display 3 not null ....
thanks in advance !!!!!
try :
select im.id, d.rank ( select t.image_id, @rownum := @rownum + 1 rank ( select image_id, count(*) cnt images_like group image_id order `cnt` desc) d ) t, (select @rownum := 0) r ) d right join images im on d.image_id = im.id
Comments
Post a Comment