Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:19:26+00:00 2026-05-29T06:19:26+00:00

What I am trying to do is equivalent to a music charts table. I

  • 0

What I am trying to do is equivalent to a “music charts” table.

I have a table of video plays, and i want to rank the videos that have been played in the last 24 hours, and compare them to the rank they were the 24 hours before that.

So the output should be the VideoID, The current Rank of the ID, and the rank the day previous of the ID

The table consists of:

PlayID (the specific id to the play table)
IP (IP address of the user who played the video)
VIDEOID (ID of the specific video, what needs to be ranked by most occurances)
playtime (linux time when played)

the table is called video_plays7d.

This has been stumping me, and i cannot figure it out, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:19:27+00:00Added an answer on May 29, 2026 at 6:19 am

    You’ll first need a full list of ALL videos so if any played on one day and not the other, you won’t loose that instance… The inner pre-query should get ALL possible video’s and their respective counts on current date or before, but the WHERE clause restricts down to just the two days. Inner query also pre-orders ITs FIRST pass by the “Day Before” count descending and applies @var to build out the rank. From THAT, requery all those results, but this time, sort by the “TODAY” count descending and apply rank to THAT set. When all is finished, it should show the ranks as of today from 1-?, but the day before ranking may be staggered respectively to their count.

    select
          AllPlays.VideoID,
          AllPlays.CntToday,
          @RankToday := @RankToday +1 as TodayRank,
          AllPlays.CntBefore,
          AllPlays.BeforeRank
       from
          ( select vp.VideoID,
                   sum(if(date(FROM_UNIXTIME(vp.playtime )) = curdate(), 1, 0 )) as CntToday,
                   sum(if(date(FROM_UNIXTIME(vp.playtime )) < curdate(), 1, 0 )) as CntBefore,
                   @RankBefore := @RankBefore +1 as BeforeRank
               from 
                  video_plays7d vp
                  join ( select @RankBefore := 0 ) SQLVars
               where
                  date( FROM_UNIXTIME(vp.playtime ) ) >= date_sub( curdate(), interval 1 day )
               group by
                 vp.VideoID
               order by
                  CntBefore DESC
          ) As AllPlays
          join ( select @RankToday := 0 ) as SqlVars2
       order by
          AllPlays.CntToday DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out if there's anything in QT that is equivalent to
I have an equivalent shell command(shown below) which I am trying to run as-is
I'm trying to figure out a DateAdd() equivalent in Oracle that is actually the
Ok, Im trying to convert a javascript timestamp to a php equivalent, I have
I'm trying to create (in r) the equivalent to the following MATLAB function that
I'm trying to create an online database of the music I locally have on
I'm trying to implement the equivalent of the ->copy(true); method that existed in Doctrine
I'm trying to find the equivalent of IsFilled=False that is used in a PathGeometry,
I've been trying to find the equivalent command for the UNIX ypcat utility for
I'm just trying to get the equivalent HTML code that represent a specific control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.