How to select data by interval of 30 minutes in mysql?

Member

by ryleigh , in category: MySQL , 6 months ago

How to select data by interval of 30 minutes in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by mallory_cormier , 6 months ago

@ryleigh 

To select data by an interval of 30 minutes in MySQL, you can make use of the INTERVAL keyword along with the MINUTE function. Here is an example query:

1
2
3
SELECT *
FROM your_table
WHERE MINUTE(your_datetime_column) % 30 = 0;


In this query, replace your_table with the name of your table, and your_datetime_column with the name of the column containing the datetime values.


The MINUTE function extracts the minute value from the datetime column, and the % operator is used to find the remainder of the division of that minute value by 30. If the remainder is 0, it means the minute is in an interval of 30 minutes.