不知道这样可不可以
select c.compname compName,sum(decode(abs(to_char(a.pdate,'yyyy')),2005,a.amount,0)) amount,---2005年5月销量---这里取去年同期销售量,是去年5月的还是4月的???
sum(decode(abs(to_char(a.pdate,'yyyy')),2004,a.amount,0)) lastAmount,
--或者这样sum(decode(extract(year from a.pdate),2004,a.amount,0)) lastAmount,---取2005年 1-12月累计销售
(select .......) totalSales,
---取去年同期累计销量
(select .......) totalLastSales,---产品等级
d.grade gradefrom t_sale_data a,t_productsort b,t_company c,t_grade dwhere a.spro_id = b.psid
and b.jg>=d.fromprice and b.jg <=d.toprice
and d.grade='二类'
and a.company_id=c.compid
and (abs(to_char(a.pdate,'yyyy'))=2005 or abs(to_char(a.pdate,'yyyy'))=2004)
and abs(to_char(a.pdate,'mm'))=5
group by c.compname,d.grade,c.compid