Here is my code, it does its job, mostly but it isn’t grouping like I told it to using an SQL statemnt. Also I was wondering how I could make a custom column that numbers itself so that the top is ‘1’ and it numbers down from there.
btnLeaderBoardUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String sql3 ="Select Name, Kills from honscores group by Name, Kills order by Kills DESC";
ResultSet rs;
try {
st = conn.prepareStatement(sql3);
rs = st.executeQuery();
table_2.setModel(DbUtils.resultSetToTableModel(rs));
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
});
Here is the output:( I want to add a column before the current two called rank and have it number from 1)
Name Kills
Raknath 20
AceFire6 15
AceFire6 12
AceFire6 10
Raknath 9
Q22 7
Q22 5
For your first issue, see below.
Short answer
Use this statement instead:
Long answer
You do not want to group by kills but only by name and want to aggregate the result.
Assuming you have this data:
and use your statement, the database will group all values for
AceFire6that have akillsvalue of2, all values forAceFire6that have akillsvalue of1, etc. and then select the amount of kills.So in the end, you will get this result:
What you want is to sum the kills up, no matter how many the person had per – I assume – game.
For your second issue (the number of rows) see this answer of another question.
Edit:
Alright, something like this should work (no guarantees, I did not test the statement):
Happy FPS-ing… 🙂