首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求和,该怎么处理

2012-03-12 
求和表里有个列叫count用selectsum(count)from表不可以我要把总和求出来,然后计算得票率VoteDAOdaonewVot

求和
表里有个列叫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 表

热点排行