ts3n_mt
ts3n_mt

Reputation: 67

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

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.

Upvotes: 2

Views: 136

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

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

Upvotes: 1

Related Questions