insert into a(art,hits) select top 10 art,hits from b order by hits desc实现的功能是把b表的点击前十条记录复制到a表,如果点击数都不一样没有问题
如果b表的点击都为0的话,复制过去的就是把所有的记录,不止10条了
要怎么样才能前十条???

解决方案 »

  1.   

    if exists (select 1 from b where hits<>0)
    insert into a(art,hits) select top 10 art,hits from b order by hits desc
    else
    insert into a(art,hits) select art,hits from b
      

  2.   

    insert into a(art,hits) select top 10 art,hits from b order by hits desc 
    加上列art 一起排序就可以解决
    insert into a(art,hits) select top 10 art,hits from b order by hits desc,art
      

  3.   

    确实会出现这个问题,出现过N次了,以前是在循环里解决,用for i=1 to 10 rs.close来解决,现在要用在一条语句里就搞不定了,上面的答案可以滴,嘿嘿,谢谢大家