How to retrieve sum of 5 top score from a table in mysql


Problem :

I am working on a project where i need to extract the sum of top 5 score for every team sorted in descending order from a table.

Here is the table structure

enter image description here

Can anyone help me for this query

Thanks



Solution :

SELECT team_id AS  `team` , (

  SELECT SUM( score ) 
  FROM  `table` 
  WHERE team_id =  `team` 
  ORDER BY score DESC 
  LIMIT 5
) AS  `score` 

FROM  `table` 
GROUP BY team_id
ORDER BY  `score`  DESC

Mysql Tutorials

Mysql Howto..

how to mysql_fetch_array on joined tables, but columns have same name [duplicate]

How to convert rows to columns and query on them in Mysql

How to join multiple condition table in MySql

How to find in MySQL the nearest (time wise) entry to a given date when only given year or only year and month?

How to merge multiple tables in mysql

ERROR 1048 (23000) Column cannot be NULL, however I am inserting valid data

How to format the returned date input value from a jQuery datepicker in order to match mysql DATE field?

how to get the total row count with mysqli

How to get last 4 inserted ID's in MySQL

How to handle Caching for huge pages using Smarty 3

How to find a string inside a huge string in a MYSQL table?

MySql & PHP - How to convert a string to DATETIME

How to find missing IDs in MySQL table [duplicate]

How should I collapse two tables into one on SELECT?

MySQL : How to make a Having clause only filter by records in a Where clause?

How to increment primary key without using Auto Increment in MySql

How to preserve mysql formatting when fetching data

How can i pass multiple radio button values to MYSQL Database via PHP as all individual values but keeping them segregated into groups?

How to manually build mysql cache

how to get top 5 for each category

how to log in to mysql and query the database from linux terminal

How to calculate the value of string in mysql [closed]

How to add relationships between tables in existing MySql database?

MySQL: How to fill new column of existing table with value based on select from another table [closed]

How to generate results from two different MySQL tables on a single graph

How to secure a connection to a remote mysql database

Is it possible to create a database in groovy when connected to a MySQL? If so, how?

how to create procedures in mysql

How to kill MySqlWorkBench process in Ubuntu?

How to use MYSQL LIMIT per person