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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:43:03+00:00 2026-06-04T16:43:03+00:00

I have a number of posts saved into a InnoDB table on MySQL. The

  • 0

I have a number of posts saved into a InnoDB table on MySQL. The table has the columns “id”, “date”, “user”, “content”. I wanted to make some statistic graphs, so I ended up using the following query to get the amount of posts per hour of yesterday:

SELECT HOUR(FROM_UNIXTIME(`date`)) AS `hour`, COUNT(date)  from fb_posts 
WHERE DATE(FROM_UNIXTIME(`date`)) = CURDATE() - INTERVAL 1 DAY GROUP BY hour

This outputs the following data:

table data

I can edit this query to get any day I want. But what I want now is the AVERAGE of each hour of every day, so that if on Day 1 at 00 hours I have 20 posts and on Day 2 at 00 hours I have 40, I want the output to be “30”. I’d like to be able to pick date periods as well if it’s possible.

Thanks in advance!

  • 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-06-04T16:43:04+00:00Added an answer on June 4, 2026 at 4:43 pm

    You can use a sub-query to group the data by day/hour, then take the average by hour across the sub-query.

    Here’s an example to give you the average count by hour for the past 7 days:

    select the_hour,avg(the_count)
    from
    (
      select date(from_unixtime(`date`)) as the_day,
        hour(from_unixtime(`date`)) as the_hour, 
        count(*) as the_count
      from fb_posts
      where `date` >= unix_timestamp(current_date() - interval 7 day)
      and created_on < unix_timestamp(current_date())
      group by the_day,the_hour
    ) s
    group by the_hour
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's what I need to fetch: - posts that have comments - number of
I have a number of classes (more than 40), each one has a number
I have a posts controller and a comments controller. Post has many comments, and
I have written a user control that captures some user input and has a
I have a table that displays data from a MySQL table. I have an
I have a web page where people are able to post a single number
I have number of line breaks in a string. But I only want it
I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number
I have a number input that should trigger jQuery on every change. To do
I have a number of classes and they are quite close to each other

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.