Home > Database > Mysql Tutorial > How can we find employees who are older than 30 years old from a MySQL table and provide the unique date of birth in the table?

How can we find employees who are older than 30 years old from a MySQL table and provide the unique date of birth in the table?

PHPz
Release: 2023-09-02 14:13:02
forward
1036 people have browsed it

我们如何从 MySQL 表中找到年龄大于 30 岁的员工,并提供表中唯一的出生日期?

To understand this concept, we will use the data from the table ‘emp_tbl’ as follows −

mysql> Select * from emp_tbl;
+--------+------------+
| Name   | DOB        |
+--------+------------+
| Gaurav | 1984-01-17 |
| Gaurav | 1990-01-17 |
| Rahul  | 1980-05-22 |
| Gurdas | 1981-05-25 |
| Naveen | 1991-04-25 |
| Sohan  | 1987-12-26 |
+--------+------------+
6 rows in set (0.00 sec)

mysql> SELECT Name,SYSDATE(),DOB,DATEDIFF(SYSDATE(),DOB)/365 AS AGE from emp_tbl WHERE(DATEDIFF(SYSDATE(), DOB)/365)>30;
+--------+---------------------+------------+---------+
| Name   | SYSDATE()           | DOB        | AGE     |
+--------+---------------------+------------+---------+
| Gaurav | 2017-12-26 22:33:24 | 1984-01-17 | 33.9644 |
| Rahul  | 2017-12-26 22:33:24 | 1980-05-22 | 37.6219 |
| Gurdas | 2017-12-26 22:33:24 | 1981-05-25 | 36.6137 |
| Sohan  | 2017-12-26 22:33:24 | 1987-12-26 | 30.0219 |
+--------+---------------------+------------+---------+
4 rows in set (0.10 sec)
Copy after login

The above is the detailed content of How can we find employees who are older than 30 years old from a MySQL table and provide the unique date of birth in the table?. 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