有一张表,本季度的数据不完整,想通过本月求上个季度的数据怎么求

关注select zzz.*
from zzz
where decode(to_char(sysdate, 'q'), '1', '4', '2', '1', '3', '2', '4', '3') =
to_char(to_date(yf, 'yyyymm'), 'q')
and decode(to_char(sysdate, 'q'),
'1',
to_char(sysdate, 'yyyy') - 1,
substr(yf, 1, 4)) = substr(yf, 1, 4)

加个开窗函数字段就好了
select zzz.*,avg(fs) over() avg_fs
from zzz
where decode(to_char(sysdate, 'q'), '1', '4', '2', '1', '3', '2', '4', '3') =
to_char(to_date(yf, 'yyyymm'), 'q')
and decode(to_char(sysdate, 'q'),
'1',
to_char(sysdate, 'yyyy') - 1,
substr(yf, 1, 4)) = substr(yf, 1, 4)