Home > database >  Used to seek common column in the average value between the adjacent two rows
Used to seek common column in the average value between the adjacent two rows

Time:11-13

Existing table is as follows:


How to evaluate the field v columns between the adjacent two rows of average? How to write SQL? The trouble give advice or comments,

CodePudding user response:

Use SQL to moving average of window function:
Writing is as follows: can directly refer to the article links:
https://blog.csdn.net/qq_41805514/article/details/81772182
 select STCD, tm, z, DRP, 
Avg (v) over (order by id
Rows 1 preceding) as moving_avg
From the Product;

CodePudding user response:

Just run, error,

CodePudding user response:

How do you write post that,

CodePudding user response:

Select STCD, tm, z, DRP, avg (dbo. CalV (z, STCD)) over (order by id rows 1 preceding) as moving_avg from T_HSYB_JYLD;

The dbo. CalV (z, STCD) is a function that is representative of v,

CodePudding user response:

I also use a avg inside with a function, you can calculate good function are listed as a subquery, avg reference column to give it a try

CodePudding user response:

Select STCD, tm, z, DRP, avg (select (dbo. CalV (z, STCD)) u from T_HSYB_JYLD) over (order by id rows 1 preceding) as moving_avg from T_HSYB_JYLD;
Can write like this?

CodePudding user response:

No,,,
Put the from T_HSYB_JYLD T_HSYB_JYLD table for you deal with the table columns

CodePudding user response:

Ok, I try to see
  • Related