http://www.cnblogs.com/jinianjun/archive/2012/06/14/2549735.html
select 后面要找的,要么在Group By后面有,要么在聚合函数有;
在select指定的字段要么就要包含在Group By语句的后面,作为分组的依据;要么就要被包含在聚合函数中。
select Name,count(*) from User Group By Name
SELECT name,sex,SUM(age)
FROM [Qiu].[dbo].[students]
group by sex
use Qiu
select sex,avg(age)
from students
group by sex