CTE中的CTE
是否可以在CTE中编写CTE?我希望它遵循这个逻辑,但解释器不喜欢它。
with outertest as( with test as ( select SRnum, gamenumber, StartOfDistribution, ApplicationNumber from #main where startofdistribution = '2011-06-14 00:00:00. and SRnum = --order by SRnum,gamenumber,StartOfDistribution,ApplicationNumber ) select ApplicationNumber count(*) as RetailerAppearance from test group by ApplicationNumber having count(*) = 4) select count(*) from outertest
解决方案:
您不能在SQL Server像这样嵌套CTE,但是,可以使用以下方法CTE:
;with test asselect SRnum, gamenumber, StartOfDistribution, ApplicationNumber from #main where startofdistribution = '2011-06-14 00:00:00.000' and SRnum =--order by SRnum,gamenumber,StartOfDistribution,ApplicationNumber),outertest asselect ApplicationNumber count(*) as RetailerAppearance from test group by ApplicationNumber having count(*) = 4) select count(*) from outertest
页:
[1]