Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to SELECT records if the absolute value of the difference between two values if greater than a certain number?

Tags:

mysql

I have two fields that are of type int lap_time_1 and lap_time_2 . Is there a mysql query to select the records whose difference (absolute value) between lap 1 and lap 2 is greater than 30?

like image 966
user784637 Avatar asked Jan 18 '12 14:01

user784637


People also ask

How do I find the absolute difference between two numbers in excel?

Subtract the expected value from the actual value (or the other way round) and get the absolute value of the difference: ABS(A2-B2)

How do you find the absolute difference?

Absolute difference and relative difference Percentages are commonly used to compare two numbers. There are two different ways to compare two objects: • The absolute difference is the actual difference between the compared value and the reference value: absolute difference = compared value − reference value.

How do I find the difference between two values in SQL?

SQL Server DIFFERENCE() Function The DIFFERENCE() function compares two SOUNDEX values, and returns an integer. The integer value indicates the match for the two SOUNDEX values, from 0 to 4. 0 indicates weak or no similarity between the SOUNDEX values. 4 indicates strong similarity or identically SOUNDEX values.

What is meant by absolute difference?

The difference, taken without regard to sign, between the values of two variables; and in particular of two random variables.


3 Answers

This assumes lap_time_1 and lap_time_2 are two columns and the data is held on the same row.

SELECT *
FROM YourTable
WHERE ABS(lap_time_1 - lap_time_2) > 30
like image 156
Andrew Avatar answered Sep 26 '22 15:09

Andrew


MySQL does have an absolute value (ABS) mathematical function. So you could do something like this:

SELECT *
FROM lap
WHERE ABS(lap_time_1 - lap_time_2) > 30;
like image 43
Aaron Avatar answered Sep 25 '22 15:09

Aaron


SELECT *
FROM MyTABLE
WHERE ABS(lap_time1 - lap_time2) > 30
like image 21
Bassam Mehanni Avatar answered Sep 22 '22 15:09

Bassam Mehanni