|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
DBaaS和其他云服务之间的区别是:DBaaS专注于提供类似关系数据库管理系统RDBMS(比如SQLServer、MySQL和Oracle)的数据库功能。事实上,RDBMS已被证明是一种适合于在各种情况下管理结构化数据的有效工具。1.盘算每一个人的总成就并排名
selectname,sum(score)asallscorefromstuscoregroupbynameorderbyallscore
2.盘算每一个人的总成就并排名
selectdistinctt1.name,t1.stuid,t2.allscorefromstuscoret1,(selectstuid,sum(score)asallscorefromstuscoregroupbystuid)t2wheret1.stuid=t2.stuidorderbyt2.allscoredesc
3.盘算每一个人单科的最高成就
selectt1.stuid,t1.name,t1.subject,t1.scorefromstuscoret1,(selectstuid,max(score)asmaxscorefromstuscoregroupbystuid)t2wheret1.stuid=t2.stuidandt1.score=t2.maxscore
4.盘算每一个人的均匀成就
selectdistinctt1.stuid,t1.name,t2.avgscorefromstuscoret1,(selectstuid,avg(score)asavgscorefromstuscoregroupbystuid)t2wheret1.stuid=t2.stuid
5.列出各门课程成就最好的先生
selectt1.stuid,t1.name,t1.subject,t2.maxscorefromstuscoret1,(selectsubject,max(score)asmaxscorefromstuscoregroupbysubject)t2wheret1.subject=t2.subjectandt1.score=t2.maxscore
6.列出各门课程成就最好的两位先生
selectdistinctt1.*fromstuscoret1wheret1.idin(selecttop2stuscore.idfromstuscorewheresubject=t1.subjectorderbyscoredesc)orderbyt1.subject
7.学号姓名语文数学英语总分均匀分
selectstuidas学号,nameas姓名,sum(casewhensubject=语文thenscoreelse0end)as语文,sum(casewhensubject=数学thenscoreelse0end)as数学,sum(casewhensubject=英语thenscoreelse0end)as英语,sum(score)as总分,(sum(score)/count(*))as均匀分fromstuscoregroupbystuid,nameorderby总分desc
8.列出各门课程的均匀成就
selectsubject,avg(score)asavgscorefromstuscoregroupbysubject
9.列出数学成就的排名
declare@tmptable(pmint,namevarchar(50),scoreint,stuidint)insertinto@tmpselectnull,name,score,stuidfromstuscorewheresubject=数学orderbyscoredescdeclare@idintset@id=0;update@tmpset@id=@id+1,pm=@idselect*from@tmp
selectDENSE_RANK()OVER(orderbyscoredesc)asrow,name,subject,score,stuidfromstuscorewheresubject=数学orderbyscoredesc
10.列出数学成就在2-3名的先生
selectt3.*from(selecttop2t2.*from(selecttop3name,subject,score,stuidfromstuscorewheresubject=数学orderbyscoredesc)t2orderbyt2.score)t3orderbyt3.scoredesc
11.求出李四的数学成就的排名
declare@tmptable(pmint,namevarchar(50),scoreint,stuidint)insertinto@tmpselectnull,name,score,stuidfromstuscorewheresubject=数学orderbyscoredescdeclare@idintset@id=0;update@tmpset@id=@id+1,pm=@idselect*from@tmpwherename=李四
12.课程不合格(-59)良(-80)优(-100)
selectsubject,(selectcount(*)fromstuscorewherescore<60andsubject=t1.subject)as不合格,(selectcount(*)fromstuscorewherescorebetween60and80andsubject=t1.subject)as良,(selectcount(*)fromstuscorewherescore>80andsubject=t1.subject)as优fromstuscoret1groupbysubject
13.数学:张三(50分),李四(90分),王五(90分),赵六(76分)
declare@svarchar(1000)set@s=select@s=@s+,+name+(+convert(varchar(10),score)+分)fromstuscorewheresubject=数学set@s=stuff(@s,1,1,)print数学:+@s由于MySQL数据库已经如此普及,对企业来说它无疑是一个更好的选择。 |
|