Jump to content

[SOLVED] Having some trouble >.>


m4x3vo

Recommended Posts

Hi, I have been trying to develop a query, first let me give you some table and column info.

The orange columns correspond to eachother, and the green columns correspond to each other.

 

The table ach contains the columns id, name, and points.

The table user_ach contains the columns ach_id and user_id.

The table users contains the columns user_id and user_character.

 

I am trying to make a high score list.  I need to start with the user_id of the first user.  The query must then go through the table user_ach and search for all the ach_id's(each is its own row) that correspond to the user_id.  Then I must use those ach_id's and go into the table ach which contains the points each ach_id is worth.  I must add all the points the user has.  I have to do this for each user id.  And when I am done, I have to order the users who have the most points (descending) and limit the query to 10 results.  The table should show their character which is the column user_character and their total amount points.

 

I guess a join would make sense, and I have been playing around with code, and am yet to get something to work.  Looking for help lol.

Link to comment
Share on other sites

Something like this??

 

SELECT
    `users`.`user_character`
    , SUM(`ach`.`points`) AS total_points
FROM
    `user_ach`
    INNER JOIN `ach` 
        ON (`user_ach`.`ach_id` = `ach`.`id`)
    INNER JOIN `users` 
        ON (`users`.`user_id` = `user_ach`.`user_id`)
GROUP BY `users`.`user_character`
ORDER BY `users`.`user_character` ASC, SUM(`ach`.`points`) DESC LIMIT 0,10;

Link to comment
Share on other sites

Something like this??

 

SELECT
    `users`.`user_character`
    , SUM(`ach`.`points`) AS total_points
FROM
    `user_ach`
    INNER JOIN `ach` 
        ON (`user_ach`.`ach_id` = `ach`.`id`)
    INNER JOIN `users` 
        ON (`users`.`user_id` = `user_ach`.`user_id`)
GROUP BY `users`.`user_character`
ORDER BY `users`.`user_character` ASC, SUM(`ach`.`points`) DESC LIMIT 0,10;

 

WOW that worked exactly, thanks so much!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.