日期:2014-05-18  浏览次数:20620 次

求和
表里有个列叫count   用select   sum(count)   from   表   不可以
我要把总和求出来,然后计算得票率


VoteDAO   dao=new   VoteDAO();
Vote   vote=new   Vote();
List   list=dao.getSession().createQuery( "     from   Vote   ").list();
Iterator   it=list.iterator();
int   sum=0;
while(it.hasNext()){
vote=(Vote)it.next();
if(vote.getCount()!=null){
out.println(sum+=vote.getCount());           这句每次的结果都不一样,因为下一次的结果还没有加上,而且也不是总和.有什么办法解决吗?
}                                                                          
out.println( " <tr> ");
out.println( " <td> "+vote.getItem()+ " </td> ");
out.println( " <td>   得票: "+vote.getCount()+ " </td> ");
out.println( " <td> 得票率: <img   src= 'web/back.gif '   height= '8 '   width= ' "+vote.getCount()+ " '%   </td> ");
out.println( " </tr> ");

}

------解决方案--------------------
select sum( "count ") from 表