I want to get the sum of a column whose dates are same.
Date Charges
3/8/2012 200
3/8/2012 400
4/8/2012 300
4/8/2012 100
<%stat=con.createStatement();
rs=stat.executeQuery("select * from pat.dbo.PHPL");
while(rs.next())
{
date=rs.getString("Date");
charges=rs.getString("Charges");%>
<table>
<tr>
<td><%=date%></td>
<td><%=charges%></td>
<%}%>
</tr></table>
Want this result:
Date Charges
3/8/2012 600
4/8/2012 400
I want this with jsp not in sql query. As I set datatype of charges as String in database. So sum was not be possible in query.
Thanks.
You don’t give any information about dbms you are using but, by your original query, I assume you are using sqlserver from Microsoft.
So, you can write:
select date, sum(cast(charges as float)) from pat.dbo.PHPL group by date.
See this link:
http://msdn.microsoft.com/en-us/library/aa226054%28v=sql.80%29