T-SQL语法错误,求助!
select @v1=avg(b)
from (select c1,sum(c2) as b
from t
group by c1
having sum(c2)>=@v2);
提示有语法错误,不知原因,求高手解惑。
鞠躬!
------解决方案--------------------select @v1=avg(b)
from (select c1,sum(c2) as b
from t
group by c1
having sum(c2)>=@v2) a
------解决方案--------------------from(子查询,没有表别名)
declare @v1 int,@v2 int
select @v1=avg(b) from
(
select c1,sum(c2) as b
from t
group by c1
having sum(c2)>=@v2)
)a
------解决方案--------------------select @v1=avg(b)
from (select c1,sum(c2) as b
from t
group by c1
having sum(c2)>=@v2) as t
------解决方案--------------------在MSSQL里面FROM后面跟的是表名,在楼主的例子当中,后面的子查询就是作为一个表在使用。。所以要给后面的子查询一个表名
如下:
declare @v1 int
declare @v2 int
select @v1=avg(b)
from (select c1,sum(c2) as b
from t
group by c1
having sum(c2)>=@v2)a;
试试