|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
与数据库相关的流程的逐渐标准化,使得解决方案提供商能以更便捷的方式提供服务、部署应用程序、规划容量和管理资源。DBaaS模式还有助于减少数据和数据库的冗余度并提升整体服务质量。效果如图所示:
测试sql语句以下:
复制代码代码以下:
declare@tabtable(Classvarchar(20),Studentvarchar(20),Coursevarchar(50),Quantitydecimal(7,2));
insertinto@tab(Class,Student,Course,Quantity)values("A班","张三","语文",60);
insertinto@tab(Class,Student,Course,Quantity)values("A班","张三","数学",70);
insertinto@tab(Class,Student,Course,Quantity)values("A班","张三","英语",80);
insertinto@tab(Class,Student,Course,Quantity)values("A班","李四","语文",30);
insertinto@tab(Class,Student,Course,Quantity)values("A班","李四","数学",40);
insertinto@tab(Class,Student,Course,Quantity)values("A班","李四","英语",50);
insertinto@tab(Class,Student,Course,Quantity)values("B班","王五","语文",65);
insertinto@tab(Class,Student,Course,Quantity)values("B班","王五","数学",75);
insertinto@tab(Class,Student,Course,Quantity)values("B班","王五","英语",85);
insertinto@tab(Class,Student,Course,Quantity)values("B班","赵六","语文",35);
insertinto@tab(Class,Student,Course,Quantity)values("B班","赵六","数学",45);
insertinto@tab(Class,Student,Course,Quantity)values("B班","赵六","英语",55);
select*from@tab
select
(casewhenGrouping(Class)=1then"总均匀"whenGrouping(Student)=1then""elseClassend)asClass
,(casewhenGrouping(Class)=1then""whenGrouping(Student)=1then"均匀"elseStudentend)asStudent
,avg(语文)as语文
,avg(数学)as数学
,avg(英语)as英语
,avg(总分)as总分
from(
selectClass,Student
,(selectisnull(sum(Quantity),0)from@tabwhereClass=t.ClassandStudent=t.StudentandCourse="语文")as"语文"
,(selectisnull(sum(Quantity),0)from@tabwhereClass=t.ClassandStudent=t.StudentandCourse="数学")as"数学"
,(selectisnull(sum(Quantity),0)from@tabwhereClass=t.ClassandStudent=t.StudentandCourse="英语")as"英语"
,(selectisnull(sum(Quantity),0)from@tabwhereClass=t.ClassandStudent=t.Student)as"总分"
from@tabast
groupbyClass,Student
)astempTab
groupbyClass,Student,语文,数学,英语,总分withrollup
havingGrouping(语文)=1
andGrouping(数学)=1
andGrouping(英语)=1
如果表有1000个记录,通过索引查找记录至少要比顺序扫描记录快100倍。 |
|