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

  • SEARCH
  • Home
  • 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 7400459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:15:13+00:00 2026-05-29T04:15:13+00:00

) I am making a SQL query to display a high score list of

  • 0

)

I am making a SQL query to display a high score list of several users scores per user, that also should give a avarage stars the specific user have achived, and the MAX level reached, and also I would like to make a calculation of the total time the user has spent in the game by summing all the time per levels..

I have the following issues:

1 : My SQL Query does not give me one line per user.

2 : The sums that are ginving is not per user but a sum of all users.

3 : The avarage STARS are not displaying with decimal.

4 : I cannot get the “score.time_spent” to calculate the sum of all the time the specific user has been playing

My SQL Query at pressent time is looking like this:

SELECT DISTINCT
game_users.username AS 'User Name',
'Level Reached' = (SELECT DISTINCT MAX(score.game_level) FROM score
        WHERE score.game_users_id IN
        (SELECT game_users_id FROM game_users
        WHERE game_users.id = score.game_users_id)),
score.time_spent AS 'Total Time Spent',
'Stars' = (SELECT DISTINCT AVG(score.stars) FROM score
        WHERE score.game_users_id IN
        (SELECT game_users_id FROM game_users
        WHERE game_users.id = score.game_users_id)),
'High Score' = (SELECT DISTINCT SUM(score.game_level_score) FROM score
        WHERE score.game_users_id IN
        (SELECT game_users_id FROM game_users
        WHERE game_users.id = score.game_users_id)),
game_users.current_state AS 'Online State'          
FROM
game_users
INNER JOIN score ON game_users.id = score.game_users_id
GROUP BY
game_users.id,
game_users.username,
score.game_level_score,
score.game_level,
score.time_spent,
score.stars,
game_users.current_state
GO

The “game_users” table looks like this:

id                      int     Unchecked
firstname       varchar(100)    Checked
lastname        varchar(100)    Checked
email           varchar(100)    Checked
username        varchar(50)     Checked
usr_pass        varchar(50)     Checked
current_state           int     Checked

The “score” table looks like this:

id                         int      Unchecked
game_users_id              int      Unchecked
game_level          varchar(4)      Checked
game_level_score    numeric(18, 0)  Checked
stars                      int      Checked
time_spent             time(7)      Checked

Can someone help me out in this mess? 🙂

Best Regards

Stig 🙂

  • 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-29T04:15:13+00:00Added an answer on May 29, 2026 at 4:15 am

    Looks like this should solve it:

    SELECT a.username AS 'User Name'
        , MAX(b.game_level) AS 'Level Reached'
        , CAST(DATEADD(millisecond,SUM(DATEDIFF(millisecond,0,CAST(b.time_spent AS DATETIME))),0) AS TIME) AS 'Total Time Spent'
        , AVG(CAST(b.stars AS FLOAT)) AS 'Stars'
        , SUM(b.game_level_score) AS 'High Score'
        , a.current_state AS 'Online State'
    FROM game_users a
    JOIN score b
        ON a.id = b.game_users_id
    GROUP BY a.username, a.current_state
    

    Note: the CAST line is from this site – http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=121027

    EDIT: Casted stars as float.

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

Sidebar

Related Questions

I am making an app that lets user define their own data source (SQL),
We are trying to build a SQL query builder that would allow users to
I have an sql query that requires repeating the same SELECT statement a number
I've got an sql query that pulls locations from a database based on coordinates
I'm trying to make a Teradata SQL query that will return the n -th
I have two long type columns that I want to concat during sql query.
I have a SQL query that compares a value in the database to a
I'd like to give a user the option of making SQL queries. I placed
After making a SQL query to Table Post I wish to hydrate the $result
I've used answer from this question: Django: making raw SQL query, passing multiple/repeated params?

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.