Sql Group by 使用
生活随笔
收集整理的這篇文章主要介紹了
Sql Group by 使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
CREATE TABLE StuCourseScore ( ID int, Name nvarchar(10), Course nvarchar(10), Score int ) INSERT StuCourseScore VALUES(1,'張三','語文',80) INSERT StuCourseScore VALUES(1,'張三','數(shù)學',89) INSERT StuCourseScore VALUES(1,'張三','英語',90)INSERT StuCourseScore VALUES(2,'李四','語文',100) INSERT StuCourseScore VALUES(2,'李四','數(shù)學',79) INSERT StuCourseScore VALUES(2,'李四','英語',95)SELECT * FROM StuCourseScoreSELECT --group的字段或者聚合函數(shù)ID, sum(casewhen Course='語文' then Scoreend) as "語文成績",sum(casewhen Course='數(shù)學' then Scoreend) as "數(shù)學成績",sum(casewhen Course='英語' then Scoreend) as "英語成績" FROM StuCourseScore GROUP BY ID--以后名字加上 SELECT Name FROM StuCourseScore group BY Name
轉(zhuǎn)載于:https://www.cnblogs.com/leee/p/4985710.html
總結(jié)
以上是生活随笔為你收集整理的Sql Group by 使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第三章 可扩展标记语言XML
- 下一篇: WEB 服务器配置