我尝试创建cte但我觉得在执行它时总是遇到麻烦。我仔细检查了我的代码,一切看起来都对我。虽然我单独在cte中运行脚本,但它运行正常。但是当我把它放在一个cte中时,它说“附近的语法不正确”)“”
有谁知道为什么会这样?我的所有()应该工作正常。请帮忙!
脚本:
WITH cte AS
(
select a.custid,count(a.orderid),rank() over (order by count(a.orderid) desc) as 'num'
from sales.orders a
group by a.custid
)
select * from cte
答案 0 :(得分:4)
您是否尝试过添加“;”在WITH?前面用分号?
;WITH cte AS
(
select a.custid,count(a.orderid) AS OrderCount,rank() over (order by count(a.orderid) desc) as 'num'
from sales.orders a
group by a.custid
)
select * from cte