String sql="select id,ball,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id,ball";
1.我想按timedata的顺序把同一天内的ball(金额)加一块。
但是改语句运行以后是antimedata排列但是金额没有累计
求解
1.我想按timedata的顺序把同一天内的ball(金额)加一块。
但是改语句运行以后是antimedata排列但是金额没有累计
求解
String sql="select id,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id";
//ball参与聚合,不用出现在group by中
对,还没注意你的ball出现在了分组后面
ball int 2
timedata varchar 3
{
try
{
show.setShowpage(showpage);
int pagesize=show.getPagesize();
Statement st=conn.createStatement();
String sql="select id,timedata,sum(ball) as total from buy where timedata between '"+date1+"' and '"+date2+"' group by timedata,id";
ResultSet rs=st.executeQuery(sql);
rowSet=new CachedRowSetImpl();
rowSet.populate(rs);
conn.close();
show.setRowSet(rowSet);
rowSet.last();
int m=rowSet.getRow();
int n=pagesize;
int pageallcount=((m%n)==0?(m/n):(m/n+1));
show.setPageallcount(pageallcount);
pageresult=shows(showpage,pagesize,rowSet);
show.setPageresult(pageresult);
}
catch (SQLException e1)
{
System.out.print(e1+" err1");
}
System.out.print(date1);
System.out.print(date2); RequestDispatcher rd=request.getRequestDispatcher("extend/allinfo.jsp");
rd.forward(request, response);
}
if(z==2)
{
try
{
}
catch (Exception e2)
{
System.out.print(e2+" err2");
}
}
if(z==3)
{
try
{
}
catch (Exception e3)
{
System.out.print(e3+" err3");
}
}
} public StringBuffer shows(int page,int pagesize,CachedRowSetImpl rowSet)
{
StringBuffer st=new StringBuffer();
try
{
rowSet.absolute((page-1)*pagesize+1);
for(int i=1;i<=pagesize;i++)
{
st.append("<tr>");
st.append("<td>"+rowSet.getInt(1)+"</td>");
// st.append("<td>"+rowSet.getString(2)+"</td>");
// st.append("<td>"+rowSet.getString(3)+"</td>");
// st.append("<td>"+rowSet.getString(4)+"</td>");
// st.append("<td>"+rowSet.getString(5)+"</td>");
// st.append("<td>"+rowSet.getInt(6)+"</td>");
// st.append("<td>"+rowSet.getString(7)+"</td>");
// st.append("<td>"+rowSet.getInt(8)+"</td>");
// st.append("<td>"+rowSet.getInt(9)+"</td>");
st.append("<td>"+rowSet.getInt(2)+"</td>");
st.append("<td>"+rowSet.getString(3)+"</td>");
st.append("<tr>");
if(rowSet.next()==false) break;
}
}
catch(SQLException e4)
{
System.out.print(e4+" err4");
}
return st;
}
}
from buy
group by id,timedata在SQL查询分析器中运行得到的结果集是不是楼主需要的。
from tb
where timedata between ... and ...
group by convert(varchar(10),timedata,120)