# SQL statement to calculate difference between specified value and all other values of one field

**URL:** <https://community.influxdata.com/t/sql-statement-to-calculate-difference-between-specified-value-and-all-other-values-of-one-field/9346>\
**Category:** InfluxDB 2\
**Created:** [April 7, 2019, 12:36am UTC](https://community.influxdata.com/t/sql-statement-to-calculate-difference-between-specified-value-and-all-other-values-of-one-field/9346 "2019-04-07T00:36:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Reis](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/michael_reis/32/2717_2.png) [@Michael\_Reis](https://community.influxdata.com/u/Michael_Reis)\
**Post date:** [April 7, 2019, 12:36am UTC](https://community.influxdata.com/t/sql-statement-to-calculate-difference-between-specified-value-and-all-other-values-of-one-field/9346/1 "2019-04-07T00:36:57Z")

</div>

I’m trying to come up with a query that’s similar to the InfluxDB Difference function, except that rather than calculating the difference between subsequent field values, it would calculate the difference with respect to a specific field value.  
I’m using InfluxDB to store performance test statistics, and I’d like to see the difference of each Response Time value with respect to a baseline Response Time value.

Say I had a measurement consisting of the 2 fields, “Date” and “Resp Time”, and the data looks like this:

| Date | Resp Time |  
| 1/1/2019 | 4 |  
| 1/2/2019 | 7 |  
| 1/3/2019 | 3 |  
| 1/4/2019 | 9 |  
| 1/5/2019 | 2 |

The 1/3/2019 row contains the Resp Time value that I’d like to compare each of the other Resp Time values to.  
I would like an output that looks something like this:

| Date | Resp Time | | Difference |  
| 1/1/2019 | 4 | | 1 |  
| 1/2/2019 | 7 | | 4 |  
| 1/3/2019 | 3 | | 0 |  
| 1/4/2019 | 9 | | 6 |  
| 1/5/2019 | 2 | | -1 |

I was thinking of a query like this but I don’t think I can reference different table aliases in the Select portion of an InfluxDB query:

SELECT t1.Date, t1.RespTime, t1.RespTime-t2.RespTime AS Difference  
FROM Table1 AS t1, Table1 AS t2  
WHERE t2.Date=“1/3/2019”

Any thoughts would be much appreciated.
