Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-2008, 02:30 PM
Ciaran
 
Posts: n/a
Default Select records around a specific record?

Hi,
I'm working on a big scoreboard which I'm hoping to split into several
pages. My question is:
Is there a simple way to take a column value and select the 10 values
higher than it and the 10 values lower than it from the table using
mysql?

Here's my query so far in case you want to have a look at it: (This
just selects all scores)

SELECT
records.recordID,
max(records.score) as score,
records.playerID,
players.name AS playername,
teams.name AS teamname,
(SELECT SUM(score) FROM records WHERE teamID=teams.teamID) AS
teamscore
FROM records
LEFT JOIN players ON players.playerID = records.playerID
LEFT JOIN teams ON teams.teamID = records.teamID
GROUP BY records.playerID
ORDER BY records.score DESC

Thanks for any help!
Ciarán
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-20-2008, 04:54 PM
Michael Austin
 
Posts: n/a
Default Re: Select records around a specific record?

Ciaran wrote:
> Hi,
> I'm working on a big scoreboard which I'm hoping to split into several
> pages. My question is:
> Is there a simple way to take a column value and select the 10 values
> higher than it and the 10 values lower than it from the table using
> mysql?
>
> Here's my query so far in case you want to have a look at it: (This
> just selects all scores)
>


Select * from (
SELECT
records.recordID,
max(records.score) as score,
records.playerID,
players.name AS playername,
teams.name AS teamname,
(SELECT SUM(score) FROM records WHERE teamID=teams.teamID) AS
teamscore
FROM records
LEFT JOIN players ON players.playerID = records.playerID
LEFT JOIN teams ON teams.teamID = records.teamID
GROUP BY records.playerID
ORDER BY records.score DESC
) tmp
where tmp.score between [somescore]+10 and [somescore]-10;

>
> Thanks for any help!
> Ciarán


yw.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:40 PM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.