Select*fromstudentmarkswhereabs(Hindi-English)>10;+--------+-------+---------+------+- --------+-----------+|Name|Hindi|English|Math|Physics|Chemistry|+--------+-----"/> Select*fromstudentmarkswhereabs(Hindi-English)>10;+--------+-------+---------+------+- --------+-----------+|Name|Hindi|English|Math|Physics|Chemistry|+--------+-----">

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

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
WBOYforward
2023-08-28 19:57:121415browse

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete