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

  • Home
  • SEARCH
  • 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 7641683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:59:11+00:00 2026-05-31T08:59:11+00:00

I have a table which holds all views for the last 24 hours. I

  • 0

I have a table which holds all views for the last 24 hours. I want to pull all pages ordered by a rank. The rank should be calculated something like this:

rank = (0.3 * viewsInCurrentHour) * (0.7 * viewsInPreviousHour)

I want the prefferably in one single query. Is this possible, or do I need to make 2 queries (one for the current hour and one for the last hour and then just aggregate them)?

Here is the DESCRIBE of the table accesslog:

+-----------+------------------+------+-----+---------+----------------+
| Field     | Type             | Null | Key | Default | Extra          |
+-----------+------------------+------+-----+---------+----------------+
| aid       | int(11)          | NO   | PRI | NULL    | auto_increment |
| sid       | varchar(128)     | NO   |     |         |                |
| title     | varchar(255)     | YES  |     | NULL    |                |
| path      | varchar(255)     | YES  |     | NULL    |                |
| url       | text             | YES  |     | NULL    |                |
| hostname  | varchar(128)     | YES  |     | NULL    |                |
| uid       | int(10) unsigned | YES  | MUL | 0       |                |
| timer     | int(10) unsigned | NO   |     | 0       |                |
| timestamp | int(10) unsigned | NO   | MUL | 0       |                |
+-----------+------------------+------+-----+---------+----------------+
  • 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-31T08:59:12+00:00Added an answer on May 31, 2026 at 8:59 am
    select
        url,
        sum(timestamp between subdate(now(), interval 2 hour) and subdate(now(), interval 1 hour)) * .3 +
        sum(timestamp between subdate(now(), interval 1 hour) and now()) * .7 as rank
    from whatever_your_table_name_is_which_you_have_kept_secret
    where timestamp > subdate(now(), interval 2 hour)
    group by url
    order by rank desc;
    

    The sum(condition) works because in mysql trye is 1 and false is 0, so summing a condition is the same as what some noobs write as sum(case when condition then 1 else 0 end)

    Edit:

    Note the addition of where timestamp > subdate(now(), interval 2 hour) to improve performance, because only these records contribute to the result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table called paper , which holds all the information for
I have a table which holds images of children. Now I want to read
I have a base table called users which holds all common information about a
I have a table RecentChanges which holds reference to all actions done on my
I have a companies table which holds all the companies that my company does
I have two tables, one table is the items container, which holds all data
I have a table which holds a list of criminal charges.These charges can be
I have a games table which holds the data about a game. Then another
I have a table called Town which holds a relation between player and a
I have a parent table called 'Website' which holds records about websites. I have

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.