select 日期,拒收冷却值,b.前3日冷却平均值,拒收量 from 表a , ( select avg(冷却值) from 表a where 日期<(select 日期 from 表a where 重量=‘空白’) and 日期>(select 日期-3 from 表a where 重量=‘空白’) )b where 表a.重量=‘空白’注明:这个sql只适合重量有一个空白行记录,假如不止一条重量为空白的记录,可以根据需求取最大或者最小的来做判断:select 日期,拒收冷却值,b.前3日冷却平均值,拒收量 from 表a , ( select avg(冷却值) from 表a where 日期<(select min(日期) from 表a where 重量=‘空白’) and 日期>(select min(日期)-3 from 表a where 重量=‘空白’) )b where 表a.重量=‘空白’或者select 日期,拒收冷却值,b.前3日冷却平均值,拒收量 from 表a , ( select avg(冷却值) from 表a where 日期<(select max(日期) from 表a where 重量=‘空白’) and 日期>(select max(日期)-3 from 表a where 重量=‘空白’) )b where 表a.重量=‘空白’
from 表a ,
( select avg(冷却值)
from 表a
where 日期<(select 日期 from 表a where 重量=‘空白’)
and 日期>(select 日期-3 from 表a where 重量=‘空白’)
)b
where 表a.重量=‘空白’注明:这个sql只适合重量有一个空白行记录,假如不止一条重量为空白的记录,可以根据需求取最大或者最小的来做判断:select 日期,拒收冷却值,b.前3日冷却平均值,拒收量
from 表a ,
( select avg(冷却值)
from 表a
where 日期<(select min(日期) from 表a where 重量=‘空白’)
and 日期>(select min(日期)-3 from 表a where 重量=‘空白’)
)b
where 表a.重量=‘空白’或者select 日期,拒收冷却值,b.前3日冷却平均值,拒收量
from 表a ,
( select avg(冷却值)
from 表a
where 日期<(select max(日期) from 表a where 重量=‘空白’)
and 日期>(select max(日期)-3 from 表a where 重量=‘空白’)
)b
where 表a.重量=‘空白’