mysql – Calc between 2 Cols in Similar Desk with Totally different The place Standards?
I’ve a desk with these rows:
|dt (DateTime – every row is exclusive and 1min aside)|
|E (Decimal Worth)|
|C (Decimal Worth)|
|S (Integer Worth of both 1 or 3)|
I want this :
AVG(T1.C – T3.E)
WHERE MIN(T1.id) > T3.id
^^^ That is simply an instance of how I believe it must be finished, however am VERY open to a greater manner!)^^^
So the T1/T3 tables are merely derived from the principle desk (T) utilizing:
(SELECT * FROM T WHERE S = 1) AS T1
(SELECT * FROM T WHERE S = 3) AS T3
- S = 1 for the id/row that C is pulled from
- S = 3 for the id/row that E is pulled from
- id/row for E Must be > the row/id for C YEARWEEK(dt) for the
- id/row that C is pulled from must = the YEARWEEK(dt) of the row that E is pulled from.
I am unable to be a part of them on id or dt as every row has a novel worth.
The best way I have been making an attempt to perform that is to separate the unique desk into both Temp Tables or subqueries however nothing will deliver all of it collectively.