SQLsever中select * from (
SELECT A.fyear,A.fperiod,A.fdate,A.fcompany,A.findex,A.findexcode,A.fyear_ys,B.fmonth,B.fmonth_sj,B.fmonth_ys,B.fmonth_tq
FROM (
SELECT
fyear,fperiod,fdate,A.fcompany,A.findex,A.findexcode,fyear_ys,f1month,f2month,f3month,f4month,f5month,f6month,f7month,f8month,f9month,f10month,f11month,f12month,fstatus,
f1month_ys,f1month_tq,f2month_ys,f2month_tq,f3month_ys,f3month_tq,f4month_ys,f4month_tq,
f5month_ys,f5month_tq,f6month_ys,f6month_tq,f7month_ys,f7month_tq,f8month_ys,f8month_tq,f9month_ys,f9month_tq,
f10month_ys,f10month_tq,f11month_ys,f11month_tq,f12month_ys,f12month_tq
from WEGO_CW_SaleOut_SJ a
inner join WEGO_CW_SaleOut_YS b
ON a.fcompany=b.fcompany AND a.findexcode=b.findexcode
)A
CROSS APPLY (
VALUES
('01',f1month, f1month_ys, f1month_tq),
('02',f2month, f2month_ys, f2month_tq),
('03',f3month, f3month_ys, f3month_tq),
('04',f4month, f4month_ys, f4month_tq),
('05',f5month, f5month_ys, f5month_tq),
('06',f6month, f6month_ys, f6month_tq),
('07',f7month, f7month_ys, f7month_tq),
('08',f8month, f8month_ys, f8month_tq),
('09',f9month, f9month_ys, f9month_tq),
('10',f10month, f10month_ys, f10month_tq),
('11',f11month, f11month_ys, f11month_tq),
('12',f12month, f12month_ys, f12month_tq)
) AS B (fmonth, fmonth_sj,fmonth_ys, fmonth_tq)
) AAA
where fperiod=(select MAX(fperiod) from AAA ) and fdate= (select MAX(fdate) from AAA ) 中AAA无效
最新发布