このクエリには平均 4 秒かかります。これはストアド プロシージャのサブクエリになり、1 秒未満で実行する必要があります。クエリは次のとおりです。
(select customercampaignname + ' $' + convert(varchar, cast(amount as numeric(36,2) ) ) As 'Check_Stub_Comment2' from (
select ROW_NUMBER() OVER (ORDER BY amount desc) as rownumber, customercampaignname, amount from (
select * from (
select distinct d.customercampaignname
,sum(d.mastercurrencyamount) As amount
from bb02_donation d
JOIN bb02_donationline dl on d.donationid = dl.donationid
JOIN bb02_fundraiserrevenuestream frs on dl.fundraiserrevenuestreamid = frs.fundraiserrevenuestreamid and frs.fundraiserid = 1869
where d.customercampaignname is not null
and d.customercampaignname != ''
group by d.CustomerCampaignName
) as x
) as sub ) as y where rownumber = 1)