dbTalk Databases Forums  

how to count group maked by group by clause?

comp.databases.mysql comp.databases.mysql


Discuss how to count group maked by group by clause? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mariano C.
 
Posts: n/a

Default how to count group maked by group by clause? - 05-17-2011 , 10:16 AM






I have a table called goals structured as follow:
id (PK)
player_id (FK)
match_id (FK)

For a given player_id, i want to know how many goals has scored (every
row is a goal) and how may matches have played (every group of
match_id is a match played). How to do that?

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: how to count group maked by group by clause? - 05-17-2011 , 12:07 PM






On 2011-05-17 17:16, Mariano C. wrote:
Quote:
I have a table called goals structured as follow:
id (PK)
player_id (FK)
match_id (FK)

For a given player_id, i want to know how many goals has scored (every
row is a goal) and how may matches have played (every group of
match_id is a match played). How to do that?

select player_id,
count(1) as nr_goals,
count(distinct match_id) as nr_matches
from goals
group by player_id;


/Lelle

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.