nvl(count(item_name),0)可以改为count(*)
因为你是求记录数,而且count是不可能为NVL的

解决方案 »

  1.   

    order by id
    也可以去掉
      

  2.   

    我觉的可能是循环太多所以太慢,现在我想用group by分组查询,这样查询一次就能得到结果,这样行不行?
      

  3.   

    对,能用一条sql得到结果不要写成多条,更不要循环调用了. 建议写成:select item_dept,staff_id,count(*)
    from iccard.s_vote_result 
    where vote_datetime >=to_date('"&date_first&"','yyyy-mm-dd') 
    group by item_dept,staff_id
      

  4.   

    sql_2="select staff_id,count(0) "count" from iccard.s_vote_result where vote_datetime >=to_date('"&date_first&"','yyyy-mm-dd') and item_dept='"&rs1("dept_name")&"' group by staff_id order by id"
      

  5.   

    sql_2="select staff_id,count(0) "count" from iccard.s_vote_result where vote_datetime >=to_date('"&date_first&"','yyyy-mm-dd') and item_dept='"&rs1("dept_name")&"' group by staff_id"应该是这样,你的查询中不需要用到order by id