电厂(电厂名称下拉框)    时 间   从 (日期)    到 (日期)    
     
序号   电厂名称    日 期       减排量 
1      温州厂   2006-09-30    1 
2      温州厂   2006-09-29    2 我要求出时间从 2006-09-29 到 2006-09-30 ,把JPL(减排量)这个字段的和求出来,应该如何实现啊???
当然时间是可以随便输入的,可以输入不同的时间来求出这两个时间段之间的某一个字段的和。
谢谢各位朋友的解答!!! 

解决方案 »

  1.   

    select 减排量 from tablename where 日   期>=? and where 日   期<=?
      

  2.   

    public int getJplCount(Connection con,Date startDate,Date endDate,String electricityName){
      String sql = "select sum(jpl) from 表名 where 电厂_column = '" + electricityName+ "' and                     
                        时间_column between '"+startDate +"' and '"+endDate+"'";
      Statement st= con.CreateStatement();
      ResultSet rs=st.ExecuteQuery(sql);
      rs.next();
      int count = Integer.paserInt(rs.getString(1));
      st.close();
      con.close();
      return count;
    }没用工具可能有些地方没注意写错了
      

  3.   

    需要用电厂名称分组得话:select sum(减排量) from table where 日期> ='20070929' and where 日期 <='20070930' group by  电厂名称;
    不需要分组:select sum(减排量) from table where 日期> ='20070929' and where 日期 <='200709'