- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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)
Advertisements