Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize the grouping of time in sql at random intervals of 5 minutes and half an hour

Shulou Source: shulou.com Published: 2022-05-31 20:05:23 11月14日 Update

This article mainly introduces how to achieve sql time to 5 minutes and half an hour any interval grouping, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

The problem encountered in the development is to group the time by half an hour and minutes, such as counting the number of people from 08:00 to 08:30 and the number from 08:30 to 09:00. It seems that there is no such function in sql. It can be found directly from the database. Grouping in java is too low.

Think of the custom function of method 1, realize the half-hour conversion of time by yourself, and call the function during statistics.

CREATE FUNCTION `date_half_hour_ format` (in_date TIMESTAMP) RETURNS TIMESTAMPBEGIN DECLARE out_date TIMESTAMP; DECLARE s_date VARCHAR; DECLARE s_minute VARCHAR (2); DECLARE int_minute INT; SET s_minute = SUBSTRING (in_date, 15,2); SET int_minute = CAST (s_minute AS SIGNED); IF int_minute

Tags: Time quarter query hour grouping start function article middle time number of people that is method language statistics clarity value interest at the same time data database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi NVidia Huawei Shulou Information