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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:39:17+00:00 2026-06-01T12:39:17+00:00

Consider the following table: msg_id _time ————- 1 13:32 2 13:56 3 14:05 4

  • 0

Consider the following table:

msg_id  _time
-------------
1       13:32
2       13:56
3       14:05
4       15:00
5       15:17
6       15:28
7       16:40

I’m currently aggregating the number of messages per hour, as follows:

SELECT HOUR(_time) AS hour, COUNT(msg_id) AS cnt FROM messages GROUP BY hour 
ORDER BY hour

This results in a resultset as follows:

hour  cnt
---------
13    2
14    1
15    3
16    1

What I want, however, is the count per half hour:

hour   cnt
----------
13:30  2
14:00  1
14:30  0
15:00  3
15:30  0
16:00  0
16:30  1

What is the query making this possible? If necessary, I guess I could mkae a table with the half-hour times (00:00, 00:30, 01:00, 01:30, … 23:00, 23:30), but prefer not too. (And I still wouldn’t know how to use that table either).

Any help is greatly appreciated 🙂

  • 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-01T12:39:19+00:00Added an answer on June 1, 2026 at 12:39 pm

    you can use case when

    SELECT COUNT(msg_id) AS cnt, CONCAT(CAST(HOUR(_TIME) AS CHAR(2)), ':', (CASE WHEN MINUTE(_time) < 30 THEN '00' ELSE '30' END)) AS hour
    FROM messages
    GROUP BY CONCAT(CAST(HOUR(_TIME) AS CHAR(2)), ':', (CASE WHEN MINUTE(_time) < 30 THEN '00' ELSE '30' END))
    ORDER BY hour
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following table: mysql> select * from phone_numbers; +-------------+------+-----------+ | number | type
Consider the following messages table: _date message ------------------------- 2012-02-22 hello 2012-02-22 another msg! 2012-03-05
I need help with a query. Consider the following table: I need to select
Consider the following (simplyfied) table: ID NUMBER PROD_NO VARCHAR2(10) START_TIME DATE What I want
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
Consider the following table with messages. Some of them have one or more labels
Consider the following table: mysql> select * from vCountryStatus; +-------------+------------+------+---------+--------+-----------------+ | CountryName | CountryISO
Please consider the following table 'mmm': select * from mmm; Output: +-------+-------+------+ | texto
Consider the following table: create table temp ( name int, a int, b int
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.