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 Byselectselect2.Having
Countscore>1Having
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: 0827
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技術博客

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章