SQL - select top 10 rows with the highest number (counted)

Frager.

Hi I have a database full of records of players and theirs match Stats.

Example:

Database example

( number means goals scored in match )

What I'm, trying to do is, select top X players that scores most of goals in Season.

I'm trying something like this, but I think there must be another Select with select count (number) or something.

  SELECT TOP 10 [playerID]
      ,[number]
      ,[league]
      ,[yearID]
      ,[YellowCard]
      ,[RedCard]
  FROM [ms4033].[dbo].[Shooter]
  where yearID=28 AND league=4
  group by playerID

Thanks for your time :-)

Bulat

You need to SUM number field and order by it like this;

 SELECT TOP 10 
      playerID, 
      SUM([number]) as goals,
      [league],
      [yearID],
      SUM([YellowCard]) as YellowCards,
      SUM([RedCard]) as RedCards,
  FROM [ms4033].[dbo].[Shooter]
  WHERE yearID=28 AND league=4
  GROUP BY playerID, league, yearID
  ORDER BY goals DESC

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SELECT TOP 10 rows

From Dev

select top 3 highest number in each group in a table

From Dev

select top 3 highest number in each group in a table

From Dev

Select next 20 rows after top 10

From Dev

SQL select rows with number in sequence

From Dev

SQL select top counts for grouped rows

From Dev

SQL Select Top n percent rows

From Dev

How do I select top rows in SQL

From Dev

Dynamically select TOP rows in SQL Server

From Dev

oracle sql select maximum top x rows

From Dev

How to select top 10% of values in SQL

From Dev

T SQL select top 10 loop

From Dev

Return all rows where col matches that of the counted top 2

From Dev

In MariaDB how do I select the top 10 rows from a table?

From Dev

select sum of top 10 rows grouped by location column

From Dev

how to select max top 10 (n) rows with there size?

From Dev

Select top 10 rows from database and display result randomly

From Dev

SQL SERVER - select distinct random number of rows

From Dev

SQL select returning a defined number of rows

From Dev

SQL select last 10 rows in ascending order

From Dev

SQL select last 10 rows in ascending order

From Dev

SQL SERVER: TOP 10 rows per field - if less than 10 rows then display empty rows

From Dev

JOIN on multilple rows to SELECT only TOP row in SQL Sever

From Dev

Select TOP row in SQL and get 5 rows of end table

From Dev

SQL Server select (top) two rows into two temp variables

From Dev

SQL Select Query Highest Value

From Dev

Finding Top 15 or Top 10% Highest Values in Excel

From Dev

Select multiple rows with highest rank in mysql

From Dev

SELECT rows with the second highest value in a column

Related Related

HotTag

Archive