mysql - SQL Trending Data -
i trying create trending posts database call homepage.
the best way thought of doing this, making 2 integer tables.
the problem having, sorting these results.
here table looks like, keep track of last 10 trending posts.
name trending clicks post1 10 5 post2 9 15 post3 8 12 post4 7 10 post5 6 8 post6 5 8 post7 4 22 post8 3 18 post9 2 8 post10 1 8
the trending position updated every 4 hours , clicks reset 0.
from data, need pull posts in order
name trending clicks post6 5 22 post8 3 18 post2 9 15 post3 8 12 post4 7 10 post5 6 8 post9 2 8 post10 1 8 post1 10 5
here example:
name trending clicks post1 10 0 post5 6 9 post2 9 0 post3 8 0 post4 7 0 post6 5 0 post7 4 0 post10 1 3 post8 3 0 post9 2 0
i need sort these results, based on clicks if above trending position.
example: if post #8 get's more clicks position #4, take it's spot , keep order of trending, use clicks order data.
the original posts keep position until trending post has gotten more clicks position take it's place.
the problem i'm trying resolve, when reset trending data. reset data every 4 hours want keep positions , weight on each trending post.
did explain enough , can please me?
why doesnt work ?
select name, trending, clicks yourtable order clicks desc
but if want keep previous trend, need add weight column.
select name, trending, clicks, weight yourtable order ((clicks + weight) /2) desc
instead of reset trend every 4h wouldnt easy calculate clicks on last 4h. have record datatime each click
select name, count(clicks) clicks yourtable datetime > dateadd(h,-4,getdate()) group name order count(clicks) desc
Comments
Post a Comment