Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Select X of of Y in Aggregation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
howa  
View profile   Translate to Translated (View Original)
 More options 26 Feb 2007, 04:39
Newsgroups: comp.databases.mysql
From: "howa" <howac...@gmail.com>
Date: 25 Feb 2007 20:39:46 -0800
Local: Mon 26 Feb 2007 04:39
Subject: Select X of of Y in Aggregation
Consider a table like:

user_id      score
      1      90
      1      80
      1      70
      2      85
      2      80
      2      80
      .
      .

I want to select te average score of a user and will use sth
like:

SELECT avg( score )
FROM `score`
GROUP BY user_id

but sometimes, i want to select the average, but dropping the lowest N
score, how
to write the query?

thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
strawberry  
View profile   Translate to Translated (View Original)
 More options 26 Feb 2007, 13:51
Newsgroups: comp.databases.mysql
From: "strawberry" <zac.ca...@gmail.com>
Date: 26 Feb 2007 05:51:31 -0800
Local: Mon 26 Feb 2007 13:51
Subject: Re: Select X of of Y in Aggregation
On Feb 26, 4:39 am, "howa" <howac...@gmail.com> wrote:

Well here's a pretty substantial clue. Note that I've added the
primary key 'record_id' to the table to deal with ties.

SELECT count( * ) rank, a.user_id, A.score
FROM score A
JOIN score B ON ( A.user_id = B.user_id
AND A.score = B.score
AND A.record_id <= B.record_id )
OR (
A.user_id = B.user_id
AND A.score < B.score
)
GROUP BY A.user_id, A.record_id
HAVING rank <=2
LIMIT 0 , 30


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google