Oracle分组函数之ROLLUP

时间:2022-09-20 07:42:46

功能介绍:

首先是进行无字段的聚合,然后在对字段进行从左到右依次组合后聚合

创建表:

 Create Table score
(
classID Int,
studentName Varchar2(50),
subject varchar2(50),
score Int
);

插入测试数据:

 Insert Into score values (001,'小徐','语文',87);
Insert Into score values (001,'小徐','数学',98);
Insert Into score values (001,'小徐','外语',99);
Insert Into score values (002,'小吴','语文',80);
Insert Into score values (002,'小吴','数学',74);
Insert Into score values (002,'小吴','外语',65);
Insert Into score values (003,'小张','语文',89);
Insert Into score values (003,'小张','数学',78);
Insert Into score values (003,'小张','外语',84);
Insert Into score values (004,'小孙','语文',100);
Insert Into score values (004,'小孙','数学',100);
Insert Into score values (004,'小孙','外语',100);
Insert Into score values (001,'小彭','语文',87);
Insert Into score values (001,'小彭','数学',99);
Insert Into score values (001,'小彭','外语',65);
Insert Into score values (004,'小叶','语文',100);
Insert Into score values (004,'小叶','数学',100);
Insert Into score values (004,'小叶','外语',100);
Insert Into score values (003,'小刘','语文',79);
Insert Into score values (003,'小刘','数学',90);
Insert Into score values (003,'小刘','外语',65);
Insert Into score values (002,'小童','语文',96);
Insert Into score values (002,'小童','数学',93);
Insert Into score values (002,'小童','外语',97);

普通分组函数,统计每个班级的总分:

Select t.Classid, Sum(t.Score) From Score t Group By t.Classid;

查询结果:

Oracle分组函数之ROLLUP

加上Rollup,统计每个班级的总分和所有班级的总分:

Select t.Classid, Sum(t.Score) From Score t Group By Rollup(t.Classid);

查询结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAANoAAABsCAIAAACD7DvkAAAIxUlEQVR4nO2dPbKrMAyFvafMpGAraVKxDrq0LOFO2vTUzKTPBijfBrIDXsGPZVs2xiQ2weeMilwQQYgP2xCjK3oI2o1E3/dVVa3dLGCTXen9fvs7//rBJtTaPIv3+z2k+71GAZvsTZ7x//39HeBgE2pVnoHjgoDjRiXC8XU7i0nXx7T0cRXn24v/kmEL6Uu2Yb7JtWreC10vhBD2nW/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XomZqYArg6DaucChfUG+pyp4Tx2d1OlXPTDrrrhZFjc46xJTKouzCqdzoUg1SB44jjHmMHed/MAEc19vwfydKdUTIFmPmC4arebZNMJsYzADHupjyAhyDsieM/8rzWRzl5DLLJLND4WjMZ0a50RWmddaO2uAbOutZGbSO0tA6rjflBsVZG3zTrQxwpGlKH9turRPF1J/Iu+wvPOgBjjJN6WPbszW+T7w3Pga36aA48gYc4+UZOHqlKXUMORhw9E5T6hhyMODonabUMeRgLWaDQ7uSCJ4N3mdjLd6ViaJ206tb2RhwjCPgCBx3JAeOT/Vna65GTzYGHKVIWROtQKNeN5jxDK4NTuf0oHUEjqNIxW9SFEr+1KJUFjU9w2uDP6uTXg8cOGYutUwe1xrSZpDxDK8Nfr8Y5emBI0RE/99E3/NF/jXP8Nrg94s4nabhowkmcMxcSrHGeQkHG/EMrg1OC97aaoNnY8BRF1cslMeRen63Nng2Bhypurpgi4WaONo8BwXXBgeOwHGUgzANRzeL/edrg2djwHEU10fPUnC09eZfrA2ejQHHQXQqt/kgm+Jo8/xmbfBsDDjGEXAEjjsScASOOxJwBI47Utu2/wGQMtORpLVE0gAAAABJRU5ErkJggg==" alt="" />

先进行无字段的聚合(1),再对Classid聚合(3),相当于:

 Select Null, Sum(t.Score) From Score t
Union All
Select t.Classid, Sum(t.Score) From Score t Group By t.Classid;

在看看两个字段的,统计每个班级的总分、所有班级的总分和每个学生的总成绩:

Select t.classid,t.studentname,Sum(t.score) From Score t Group By Rollup(t.classid,t.studentname); 

查询结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV8AAAD7CAIAAABCLQCaAAAbAklEQVR4nO2dP3LkLBPGuZOrHHAVJ450jW8ypxxhy+nmilXlfC9A+F7AN9AX6B+IpoUQghl4nurampXQGPU0v2kQA2KEIAiiJMZxfDweF9/l+juU1e/vb3jhV7/ZJxT8n0dn/Sx+f38nd/9e0PV3KK7A+v/586eCm31Cwf95dMrPoMMsRGdZwf959Bx0+Pf1LhZ9/l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HB2omdTkTCjQAZbGQIfTMnbF2211t99Umyip7e3mw3bZJdaGMpd0+P5w+QA6wK4b6HBSxt64y27bo7k5pr1hplNSK0lsE7vqRO7AnwAdYNcNdDglAwgjnSuYSQJRUivp7q27KYYO1LKSoAMsgYEOF2RkB+M4urQgSvadp8Skk3SYxx4w7jAUr0OVNiFA+F9s/odsaSV3Iw8+Ohgl+05IKZ1eyKLongWxJnXx2MpmoMNNhtwhUn3njinSdDBLmv0Nu+8xKYoO1Lgk6AC7bqBDhLSSLhpGig6+kpP6bn8ujg5E8gA6wK4b6HBWTIPf0YFHw3iFDtY61NQ6UaADLKv/oZHuUKyy6ODreqwlqAKYDRUbnaXr0LKBDpPMhZ3c+UwmHXwljelQBGUwkzo2OkvXoWUDHfIIdIiNztJ1aNlAhzwCHWKjs3QdWjbQIY+GYfg/CeqPjLBWJl4AAAAASUVORK5CYII=" alt="" />

先进行无字段的聚合(1),再对Classid聚合(3),在对Classid和Studentname组合聚合,相当于:

 Select Null, Null, Sum(t.Score) From Score t
Union All
Select t.Classid, Null, Sum(t.Score) From Score t Group By t.Classid
Union All
Select t.Classid, t.Studentname, Sum(t.Score) From Score t Group By t.Classid, t.Studentname