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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:16:10+00:00 2026-06-03T04:16:10+00:00

Consider the following table: +———+———+————+———-+————+ | msg_id | user_id | _date | _time |

  • 0

Consider the following table:

+---------+---------+------------+----------+------------+
| msg_id  | user_id | _date      | _time    | count_for  |
+-------------------+------------+----------+------------+
|   1     | 1       | 2011-01-22 | 06:23:11 | 2011-01-22 |
|   2     | 1       | 2011-01-23 | 16:17:03 | 2011-01-24 |
|   3     | 1       | 2011-01-23 | 17:05:45 | 2011-01-24 |
|   4     | 2       | 2011-01-24 | 06:58:13 | 2011-01-24 |
|   5     | 2       | 2011-01-24 | 15:59:32 | 2011-01-24 |
|   6     | 3       | 2011-01-25 | 13:45:00 | ...        |
|   7     | 3       | 2011-01-26 | 13:22:34 | ...        |
+---------+---------+------------+----------+------------+

I want to count the number of messages per day, but messages after 16:00 this day have to count for the next day:
– msg 1 is written before 16:00 on 2011-01-22, so count_for is (same day) 2011-01-22
– msg 2 is written after 16:00 on 2011-01-23, so count_for is (next day) 2011-01-24

Obviously, I did the first 5 manually. My question is: with what query can I perform this operation automatically (in MySQL)?

  • 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-03T04:16:12+00:00Added an answer on June 3, 2026 at 4:16 am

    Something like

    SELECT count(msg_id), if(_time >= '16:00:00', _date + INTERVAL 1 DAY, _date) AS effective_date
    FROM yourtable
    GROUP BY effective_date
    

    should do the trick.

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

Sidebar

Related Questions

Consider the following table views user_id _date cnt ------------------------ 1 2011-02-10 123 1 2011-02-11
Consider the following table: msg_id _time ------------- 1 13:32 2 13:56 3 14:05 4
Consider the following messages table: _date message ------------------------- 2012-02-22 hello 2012-02-22 another msg! 2012-03-05
Consider the following database tables: Table messages with 13,000,000 rows (one row per message).
Consider the following table (tweets): +---------+------------+----------+ | user_id | _date | tweet_id | +---------+------------+----------+
Consider the following table: mysql> select * from phone_numbers; +-------------+------+-----------+ | number | type
Consider the following tweets table tweet_id user_id text ----------------------------------------- 1 1 look at my
Consider the following table with messages. Some of them have one or more labels
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
Consider the following table which has the fields - id (int) and date_created (datetime):

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.