Home > Database > Mysql Tutorial > How to use the MySQL INTERVAL() function on a table's columns?

How to use the MySQL INTERVAL() function on a table's columns?

PHPz
Release: 2023-09-12 10:21:04
forward
913 people have browsed it

如何对表的列使用 MySQL INTERVAL() 函数?

#We can use the INTERVAL() function on a column of a table by providing the first parameter as the name of the column. In this case, all values ​​in the column are compared with the values ​​given as other parameters of the INTERVAL() function and the result set is provided based on the comparison. To understand it, use data from Employee table as shown below -

mysql> Select* from employee568;
+----+--------+--------+
| ID | Name   | Salary |
+----+--------+--------+
| 1  | Gaurav | 50000  |
| 2  | Rahul  | 20000  |
| 3  | Advik  | 25000  |
| 4  | Aarav  | 65000  |
| 5  | Ram    | 20000  |
| 6  | Mohan  | 30000  |
| 7  | Aryan  |  NULL  |
| 8  | Vinay  |  NULL  |
+----+--------+--------+
8 rows in set (0.00 sec)

mysql> Select * from employee WHERE INTERVAL(ID,4) > 0;
+----+-------+--------+
| ID | Name  | Salary |
+----+-------+--------+
| 4  | Aarav | 65000  |
| 5  | Ram   | 20000  |
| 6  | Mohan | 30000  |
| 7  | Aryan |  NULL  |
| 8  | Vinay |  NULL  |
+----+-------+--------+
5 rows in set (0.00 sec)
Copy after login

The above result set has 5 rows with ID = 4 to 8 because INTERVAL function has value greater than 0 for these rows.

The above is the detailed content of How to use the MySQL INTERVAL() function on a table's columns?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template