SQL count (*) function query for a baseball data table explanation

Viewed 80

This line of code is simple and I understand what the query will return. I am trying to understand the third line of this code.

   select First 
, sum(rbi) as 'rbis' 
**, count(*) as 'num_players'** 
from #batter_stats 
group by First 
having count(*) >= 5 
order by [rbis] desc

The count(*) as 'num_players' is confusing me as to what this does in this query. Data query

The data table

Thanks you. I provided both the line of code and the data table.

1 Answers

In your code the aggregation functions

  , sum(rbi) as rbis
  ,  count(*) as num_players

agregated by column First

count(*) retunr the number of rows for the corresponding groped value

so in your case retunr the number of rows in your table for the corresponding value of olumn First

Related