查询 count(*)>=1  AND site2BEARNG<=60 @avgno1mrn=select avg(no1mrn) from map_ncs_cellcover as h1 where ncellid in (
      select top 3 ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and  nbearing<=60 
          order by ncellavgdis asc
)  group by cellid=====================================
当count(*)<=0  CN120AVGD=-1@num=select count(*) from map_ncs_cellcover as h1 where ncellid in (
      select ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and  Site2BEARING<=60 
         )  group by cellid
======================================update map_ncs_cellcover SET NC120AVGD =CASE
 when @uu<=0 then -1
 when @uu>=1 then 
 avgno1mrn from 
(
select avg(no1mrn) as avgno1mrn ,cellid from map_ncs_cellcover as h1 where ncellid in
(
      select top 3 ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and  Site2BEARING<=60 
          order by ncellavgdis asc
)  group by cellid
   
)bb where map_ncs_cellcover.cellid=bb.cellid这个结果是错误的!     请给我一个正确的答案! 谢谢各位啦

解决方案 »

  1.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  2.   

    看起来有点乱,不过在upate前可以先用select看看结果
      

  3.   

        这个@uu>1 时  NC120AVGD等于 avgno1mrn 
     
    select avg(no1mrn) as avgno1mrn ,cellid from map_ncs_cellcover as h1 where ncellid in 
    (
      select top 3 ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and Site2BEARING<=60  
      order by ncellavgdis asc
    ) group by cellid 就是不知道如何把avgno1mrn 赋值给NC120AVGD
      

  4.   


    IF @uu>1 
     BEGIN
    select avg(no1mrn) as NC120AVGD ,cellid from map_ncs_cellcover as h1 where ncellid in  
    (
      select top 3 ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and Site2BEARING<=60   
      order by ncellavgdis asc
    ) group by cellid
     END
    ELSE
     select avg(no1mrn) as avgno1mrn ,cellid from map_ncs_cellcover as h1 where ncellid in  
    (
      select top 3 ncellid from map_ncs_cellcover as h2 where h1.cellid=h2.cellid and Site2BEARING<=60   
      order by ncellavgdis asc
    ) group by cellid
    兄弟 你说的是这个意思不?