我有这样的场景,用户输入一个月,输出是那个月的销售额,然后是接下来 12 个月的销售额,我也写了这个查询
select
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),0),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),1),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),2),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),3),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),4),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),5),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),6),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),7),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),8),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),9),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),10),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),11),'mon'), sales)) "&m" ,
sum(decode(month ,to_char(add_months(to_date(&m,'mon'),12),'mon'), sales)) "&m"
from sales
m
是用户输入月份我希望别名也动态变化所以如何操作列别名任何帮助thanx