Raised This Month: $51 Target: $400
 12% 

SQL Query


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mysty
Member
Join Date: Oct 2015
Location: FUCK OFF
Old 12-20-2015 , 11:26   SQL Query
Reply With Quote #1

I'm trying to query for the rank of a player and set it as a cookie.
I'm new to SQL and I still have no idea what's the correct way to query the rank for a player.

Code:
SQL Table:

steamid            || name              || score
[U:1XXXXX]          Player X             213
[U:1XXXXX]          Player U             13
[U:1XXXXX]          Player Y             437
[U:1XXXXX]          Player Z             578
[U:1XXXXX]          Player W            487
To determine the rank, I reorder the score by descending order and count the row.

I've been trying various like
SELECT COUNT(*) OVER(ORDER BY score DESC) FROM ranks WHERE steamid = %s", clientid

or

SELECT COUNT(*) FROM ranks ORDER BY score DESC WHERE steamid = %s", clientid

What is the proper way to find out the rank of the player?
mysty is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 12-20-2015 , 12:20   Re: SQL Query
Reply With Quote #2

Quote:
Originally Posted by mysty View Post
What is the proper way to find out the rank of the player?
Usually tables have PRIMARY KEY -> id.
For every player you can store this ID.

PHP Code:
SELECT count(idFROM ranks WHERE id 10
// 10 - it's ID of player. (PRIMARY KEY) 
So you can get rank of player
__________________
neatek is offline
mysty
Member
Join Date: Oct 2015
Location: FUCK OFF
Old 12-20-2015 , 13:03   Re: SQL Query
Reply With Quote #3

Quote:
Originally Posted by neatek View Post
Usually tables have PRIMARY KEY -> id.
For every player you can store this ID.

PHP Code:
SELECT count(idFROM ranks WHERE id 10
// 10 - it's ID of player. (PRIMARY KEY) 
So you can get rank of player
Hmm I think you misunderstood, I'm trying to get the rank by the points they have. Sorry if I did not clarify properly.
mysty is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-20-2015 , 13:07   Re: SQL Query
Reply With Quote #4

I think it'd be "SELECT COUNT(*) FROM ranks WHERE score >= %d ORDER BY score DESC", where %d is the client's score
Miu is offline
neatek
AlliedModders Donor
Join Date: Jul 2010
Location: Russia
Old 12-20-2015 , 13:17   Re: SQL Query
Reply With Quote #5

Quote:
Originally Posted by Miu View Post
I think it'd be "SELECT COUNT(*) FROM ranks WHERE score >= %d ORDER BY score DESC", where %d is the client's score
better
PHP Code:
SELECT COUNT(score
it maybe faster
__________________
neatek is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode