select avg(select top 5 ziduan from tablename order by ziduan desc)
这个不行啊,sql 2000中要报错的; 还是谢谢你!
这句在sql 2000里面要报错,谢谢!
--上面写错了 select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a
----假设整数字段名称为num select avg(num) from (select top 5 num from table order by num DESC) as t
不过在游标里面这样查询好像总是报错: select @l_amount = avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ——修改成下面的就没问题了: select @l_amount = isnull( ( select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ), 0) ——为啥呢?各位高手。
不过在游标里面这样查询好像总是报错: select @l_amount = avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ——修改成下面的就没问题了: select @l_amount = isnull( ( select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ), 0) ——为啥呢?各位高手。
还是谢谢你!
select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a
select avg(num) from (select top 5 num from table order by num DESC) as t
select @l_amount = avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a
——修改成下面的就没问题了:
select @l_amount = isnull( ( select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ), 0)
——为啥呢?各位高手。
select @l_amount = avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a
——修改成下面的就没问题了:
select @l_amount = isnull( ( select avg(ziduan) from (select top 5 ziduan from tablename order by ziduan desc) a ), 0)
——为啥呢?各位高手。