I have a problem when retrieving data from a SQL using JSP.
在使用JSP从SQL检索数据时,我遇到了一个问题。
ResultSet rs = statement.executeQuery("select orderdate,
SUM(orderingcost)
from `shopping`.`order`
group by orderdate");
int count = 0;
//String
while (rs.next()) {
//String orderdate = rs.getString("orderdate");
//String orderingcost = rs.getString("orderingcost");
System.out.println(count);
count++;
}
I use group by statement to group some data.
我使用group by语句对一些数据进行分组。
However, I don't know how to get the data out when group by is applied.
然而,当group by应用时,我不知道如何获取数据。
Can anyone help me?
谁能帮我吗?
1 个解决方案
#1
4
You need to alias the column:
您需要将列别名为:
select orderdate, SUM(orderingcost) orderingcost from `shopping`.`order` group by orderdate
Then you'll have a column named orderingcost
in your resultset, and you can do:
然后在resultset中有一个名为orderingcost的列,您可以这样做:
double orderingcost = rs.getFloat("orderingcost") // probably need getFloat instead of string since it's a numeric value
#1
4
You need to alias the column:
您需要将列别名为:
select orderdate, SUM(orderingcost) orderingcost from `shopping`.`order` group by orderdate
Then you'll have a column named orderingcost
in your resultset, and you can do:
然后在resultset中有一个名为orderingcost的列,您可以这样做:
double orderingcost = rs.getFloat("orderingcost") // probably need getFloat instead of string since it's a numeric value