我有SQL代码,在其中将嵌套查询的输出分配给变量,但在)附近得到错误的语法错误
下面是代码:
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
错误:
Msg 102, Level 15, State 1, Line 53
Incorrect syntax near ')'.
不确定是什么问题
set @MAX_CNT =(select coun from (select MAX(SEQ) Coun from (
SELECT ROW_NUMBER()OVER(ORDER BY COUNTRY)SEQ,* FROM #TEMP1
)xx)y)
应将值分配给变量。
答案 0 :(得分:2)
你为什么不写这个呢?
select @MAX_CNT = count(*)
from #temp1;
不需要将窗口函数与聚合一起使用。
答案 1 :(得分:1)
set @MAX_CNT = (select MAX(SEQ) Coun from
(
SELECT ROW_NUMBER()OVER(ORDER BY id)SEQ, * FROM users
) xx)