Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:00:28+00:00 2026-05-26T23:00:28+00:00

Here is my code, it does its job, mostly but it isn’t grouping like

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:00:28+00:00Added an answer on May 26, 2026 at 11:00 pm

    For your first issue, see below.

    Short answer
    Use this statement instead:

    Select Name, sum(Kills) from honscores group by Name order by Kills DESC
    

    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:

    AceFire6  2
    AceFire6  2
    AceFire6  1
    AceFire6  3
    Raknath   1
    Raknath   1
    

    and use your statement, the database will group all values for AceFire6 that have a kills value of 2, all values for AceFire6 that have a kills value of 1, etc. and then select the amount of kills.

    So in the end, you will get this result:

    AceFire6  3
    AceFire6  2
    AceFire6  1
    Raknath   1
    

    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):

    SELECT @rn:=@rn+1 AS rank, Name, kills
    FROM (
      Select Name, sum(Kills) as kills from honscores group by Name order by Kills DESC
    ) t1, (SELECT @rn:=0) t2;
    

    Happy FPS-ing… 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code here that does not work despite me using
here is my code it shares the folder but that does not work correctly
I've seen other questions here about PNS, in terms of code, but how does
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
Here's the code, I don't quite understand, how does it work. Could anyone tell,
Here is code from MSDN . I don't understand why the work isn't just
enter code here I have a table on SQL server 2005 with bigint primary
I'am new to PHP, so please be nice :) Sometimes file_get_contents does its job
I use Visual Basic 6.0 with SQL Server 2005 Here is my code :
I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.