You can't nest CTEs like that in SQL Server but you can use multiple CTEs the following way:
;with test as
(
select
SRnum,
gamenumber,
StartOfDistribution,
ApplicationNumber
from #main
where startofdistribution = '2011-06-14 00:00:00.000'
and SRnum = '313'
--order by SRnum, gamenumber, StartOfDistribution, ApplicationNumber
),
outertest as
(
select
ApplicationNumber
,count(*) as RetailerAppearance
from test
group by ApplicationNumber
having count(*) = 4
)
select count(*)
from outertest
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…