movieprodw
asked on
Query Help - Leaders
Hello,
I have two tables
table 1: cms_members
id|username|public|challen ge
table 2: cms_activities
date|user_id|miles|trail
I need to run a query where I can select the top 10 people and display them by rank.
ie
Leaders
username - unique trails - total days - total miles
I started with this but after staring at it for 30 minutes I thought I should ask for help.
I am completely lost and would greatly appreciate any help.
Matt
I have two tables
table 1: cms_members
id|username|public|challen
table 2: cms_activities
date|user_id|miles|trail
I need to run a query where I can select the top 10 people and display them by rank.
ie
Leaders
username - unique trails - total days - total miles
I started with this but after staring at it for 30 minutes I thought I should ask for help.
SELECT
cms_members.id,
cms_members.username
FROM
cms_members
WHERE
challenge = 'ex'
AND public = 'Yes'
I am completely lost and would greatly appreciate any help.
Matt
ASKER
I am using mysql
Easy enough. :) LIMIT 10
Good Luck,
Kent
SELECT *
FROM cms_members
INNER JOIN cms_activites
ON cms_members.id = cms_activites.user_id
ORDER BY miles desc
LIMIT 10;
Good Luck,
Kent
ASKER
Hello Kdo,
Thank you for the help.
The issue is that it is not totaling the miles per user and 'ranking' them.
I hope I am explaining it correctly.
table 2: cms_activities
date|user_id|miles|trail
01/02/14|23|50|trail2
01/02/16|23|5|trail1
01/02/17|25|50|trail4
01/02/13|25|5|trail1
01/02/15|23|5|trail6
01/02/16|23|50|trail1
01/02/17|25|5|trail7
Thank you for the help.
The issue is that it is not totaling the miles per user and 'ranking' them.
I hope I am explaining it correctly.
table 2: cms_activities
date|user_id|miles|trail
01/02/14|23|50|trail2
01/02/16|23|5|trail1
01/02/17|25|50|trail4
01/02/13|25|5|trail1
01/02/15|23|5|trail6
01/02/16|23|50|trail1
01/02/17|25|5|trail7
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
ASKER
Perfect
the method of choosing the "top 10" will vary according to which SQL engine you're running, but the entire list can be chosen with:
Open in new window
Which database are you using?
Kent