count columns group by

Posted by zhangzhong on Stack Overflow See other posts from Stack Overflow or by zhangzhong
Published on 2010-04-23T11:28:14Z Indexed on 2010/04/23 11:33 UTC
Read the original article Hit count: 448

Filed under:

I hava the sql as below:

select a.dept, a.name
  from students a
 group by dept, name
 order by dept, name

And get the result:

dept   name
-----+---------
CS   | Aarthi
CS   | Hansan
EE   | S.F
EE   | Nikke2

I want to summary the num of students for each dept as below:

dept   name        count
-----+-----------+------  
CS   | Aarthi    |  2
CS   | Hansan    |  2
EE   | S.F       |  2
EE   | Nikke2    |  2
Math | Joel      |  1

How shall I to write the sql?

© Stack Overflow or respective owner

Related posts about sql