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 6834295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:05:38+00:00 2026-05-26T23:05:38+00:00

First thing, my date format for the field is TIMESTAMP I have a table

  • 0

First thing, my date format for the field is TIMESTAMP

I have a table that consists of id, domain, hits, when.

Now when I insert the hits into the database, i’m pulling from my analytics API every 10 minutes. So the content of this table is

id=1, domain=test.com, hits=930, when=2011-11-22 16:00:22;

id=2, domain=test2.com, hits=134, when=2011-11-22 16:10:22;

etc

Once this fills up with data every 10 minutes for the last six hours, I want to find the number of hits for each domain for each hour. so:

There will be 6 rows per hour since it inserts every 10 minutes, how can I retrieve the total number of hits for each hour?

If I want to pull my statistics at 1:39PM for the current hour, I should be able to pull all the hits from 1:10PM, 1:20PM, 1:30PM.

DO I need six separate mysql queries that take the current time and run it for each hour because I was be displaying it in a graph (1 hour ago, 2 hours ago, 3 hours ago, etc) or is there a simpler way to achieve this?

Please help me understand, thanks!

  • 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-26T23:05:39+00:00Added an answer on May 26, 2026 at 11:05 pm

    You could try

    select domain, date_format(when, '%Y-%m-%d %I%p') hour, sum(hits)
    from table group by domain, hour
    

    EDIT: I changed the format from %H for 24 hour clock to %I%p for 12 hour clock with AM/PM, since it seems like that’s what you want.

    EDIT2: If it’s only the last six hours you want, grouped by how many hours ago the hits were, you might be better off with (added date_format to group by whole hour)

    select domain, hour(timediff(date_format(now(), '%Y-%m-%d %H'), 
        date_format(when, '%Y-%m-%d %H'))) hours, sum(hits)
    from table
    where hours < 7
    group by domain, hours 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing my first CSV import into MySQL and noticed that the date in
First I had problems with getting date's into my db see here . Now
I want to select records that have a created date between the first and
First thing i want to say that it's not an easy question to explain,
The first thing that comes to my mind is to do a bunch of
I was just reading this line: The first thing the format() method does is
I am calling a csh script that the first thing it does is starts
I have some jQuery/JS below. The first thing to run is the alert box
I'm using Zend_Db to query a table. I have some WHERE clauses that need
I have a log file that I want to parse and load into a

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.