I have a MySQL table with two fields: date
and value
. date
is of type date, and value
is decimal(10,2).
There are "pairs" of rows (non-consecutive) whose values are of equal magnitude but opposite sign, within 7 days of each other.
date value
...
2020-06-20 123.45
...
2020-06-25 -123.45
...
The above is a "pair" because they are negatives of each other and their dates are within 7 days of each other. There may be any number of intervening rows. There may be any number of pairs in the table. Pairs of differing values may overlap 7 day periods. For simplicity assume there are no other equal-value rows also with 7 days (ie, no triples).
I'm trying to find a SELECT statement that gives me all the table's rows EXCEPT "pairs". Could someone please help?
date
one pair may exist within another pair, or one pair may include one member of another pair. I wasn't sure if this would influence the query. Basically assume nothing about the dates or values. I'm running MySQL 5.6. Thanks for mentioning "key". I checked my table - duh - I was indexing neither column. Added indexes for both columns and now the query runs in a few seconds. Cheers.