

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Round seconds to nearest half minute in MySQL?
To round seconds to nearest half minute, use CEILING(). Let us first create a table −
mysql> create table DemoTable (secondValue int); Query OK, 0 rows affected (0.64 sec)
Example
Insert some records in the table using insert command −
mysql> insert into DemoTable values(27); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values(56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(118); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-------------+ | secondValue | +-------------+ | 27 | | 56 | | 118 | +-------------+ 3 rows in set (0.00 sec)
Following is the query to round seconds −
mysql> select secondValue, CEILING(secondValue / 30) / 2 AS ApproxMinutes from DemoTable;
Output
+-------------+---------------+ | secondValue | ApproxMinutes | +-------------+---------------+ | 27 | 0.5000 | | 56 | 1.0000 | | 118 | 2.0000 | +-------------+---------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- How to round down to nearest integer in MySQL?
- Round to nearest integer towards zero in Python
- How to round to the nearest hundred in R?
- Python Pandas - How to Round the DateTimeIndex with minute frequency
- Python Pandas - How to Round the TimeDeltaIndex with minute frequency
- How to round up to the nearest N in JavaScript
- Round number down to nearest power of 10 JavaScript
- Round a number to the nearest even number in C#
- Round elements of the array to the nearest integer in Numpy
- How to round the decimal number to the nearest tenth in JavaScript?
- Python Pandas - Round the Timedelta with seconds frequency
- Python Pandas - How to Round the DateTimeIndex with seconds frequency
- Python Pandas - How to Round the TimeDeltaIndex with seconds frequency
- MySQL query to convert timediff() to seconds?
- Round records with numbers in MySQL
Advertisements