T-SQL的高级查询详解--分组查询

 

 
1.      
CourseID

SQL serverGroup BySQLSelect CourseID, Avg(Score) as From Score

 
Group By CourseID
 

 

 

SQLSelect StudentID as ,CourseID as , Avg(Score) as

 
From Score
Group By StudentID,CourseID
Group By select select 2.Having
Count score >1 Having
SQL
Select StudentID as ,CourseID as ,
Avg(Score) as
From Score
Group By StudentID,CourseID
Having Count(Score)>1
3.
WHERE
GROUP BY
HAVING
1: 2000
Select , Count(*)
From Where >= 2000
GROUP BY Having Count(*) > 1
2: 08 2 7
Select CAST (DATEPART(YEAR,paytime) as varchar(10))+' '+ CAST (DATEPART(MONTH,paytime) as varchar(10))+' ' AS ,Sum(CHARGE) From "history-accountbill Where isPaid<>0 AND
paytime between '2008-02-01 00:00:00' and '2008-7-31 23:59:59'
Group By CAST (DATEPART(YEAR,paytime) as varchar(10))+' '+ CAST (DATEPART(MONTH,paytime) as Varchar(10))+' '
 

 

本文出自 “ 风水云天--乐成 著” 博客,请务必保留此出处 http://yueyuanyuan.blog.51cto.com/1342062/308496

本文出自 51CTO.COM技术博客

 

你可能感兴趣的:(数据库,查询,分组,详解,高级)