mysql – Calc between 2 Cols in Similar Desk with Completely different The place Standards?

0
47


I’ve a desk with these rows:

T
id (PK)
dt (DateTime – every row is exclusive and 1min aside)
E (Decimal Worth)
C (Decimal Worth)
S (Integer Worth of both 1 or 3)

I would like 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 means!)^^^

So the T1/T3 tables are merely derived from the primary desk (T) utilizing:

(SELECT * FROM T WHERE S = 1) AS T1

(SELECT * FROM T WHERE S = 3) AS T3

DETAILS

  • 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 singular worth.

The way in which I have been making an attempt to perform that is to separate the unique desk into both Temp Tables or subqueries however nothing will convey all of it collectively.



Supply hyperlink

Leave a reply