虾米、木木 回复 chen(提问者)select a.Organization_id,
a.business_type,
sum(case
when to_char(purchase_year || \'-\' ||
lpad(purchase_month, 2, 0)) = \'${dates}\' then
a.amount
else
0
end) as 当期,
sum(case
when to_char(purchase_year + 1 || \'-\' ||
lpad(purchase_month, 2, 0)) = \'${dates}\' then
a.amount
else
0
end) as 同期
from Report_Cockpit_Screen_Purchase a
group by a.Organization_id, a.business_type