是否可以在CTE中编写CTE?: s e/ b* E( X( u3 U
我希望它遵循这个逻辑,但解释器不喜欢它。 : T c0 q: z7 G. Hwith 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 8 \- [2 @8 }& i解决方案: ) K! \5 X' e1 {& W; V$ ~
您不能在SQL Server像这样嵌套CTE,但是,可以使用以下方法CTE: 1 a: K7 U! d2 x: y5 ^* j5 j) K;with test as select SRnum, gamenumber, StartOfDistribution, ApplicationNumber from #main where startofdistribution = '2011-06-14 00:00:00.000' and SRnum = --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