Home > Database > Mysql Tutorial > body text

How can we select records from a table if the absolute value of the difference between two values ​​is greater than a certain number?

WBOY
Release: 2023-08-28 19:57:12
forward
1414 people have browsed it

How can we select records from a table if the absolute value of the difference between two values ​​is greater than a certain number?

If the absolute value of the difference between two values ​​is greater than a certain number, we can use the MySQL absolute value i.e. ABS() function to select records from the table. We demonstrate this using data from the "Marks" table.

Example

mysql> Select * from studentmarks where abs(Hindi-English)>10;
+--------+-------+---------+------+---------+-----------+
| Name   | Hindi | English | Math | Physics | Chemistry |
+--------+-------+---------+------+---------+-----------+
| Gaurav | 75    | 86      | 95   | 69      | 85        |
| Rahul  | 74    | 85      | 97   | 69      | 86        |
| Mohit  | 73    | 87      | 89   | 69      | 86        |
+--------+-------+---------+------+---------+-----------+
3 rows in set (0.00 sec)
Copy after login

The above result set only contains records where the absolute value of the difference between the two subjects English and Hindi is greater than 10.

The above is the detailed content of How can we select records from a table if the absolute value of the difference between two values ​​is greater than a certain number?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!