This is the table that I have: table name: player. all data type are float
id | pts | gp
0 | 45 | 5
1 | 13 | 6
2 | 74 | 10
I want to select the avg of the points. here's the function i used on button click after connecting to the db.
public float getavgstats() {
float ptsavg = 0;
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select (cast((pts/gp) as decimal(10,2))) as ppg from player order by ppg desc");
while (rs.next()) {
ptsavg = rs.getFloat("pts");
System.out.println(ptsavg);
}
} catch (Exception ex) {
System.out.println("error" + ex);
}
return ptsavg;
}
}
I'm getting an error that the column 'pts' is not found
Your query returns only one column - ppg
, it doesn't have a pts
column in it.
If you want to query it, you should add it to your query:
ResultSet rs = stmt.executeQuery(
"select pts, (cast((pts/gp) as decimal(10,2))) as ppg " +
// Here-^
"from player order by ppg desc");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.