oracle group by语句实例测试
程序员文章站
2023-12-03 17:25:34
sql代码 复制代码 代码如下: create table test(a varchar2( 20),b varchar2 (20),c number,d varchar2...
sql代码
create table test(a varchar2( 20),b varchar2 (20),c number,d varchar2 (20))
insert into test values( 'a1','b1' ,1, 't');
insert into test values( 'a3','b3' ,3, 't');
insert into test values( 'a4','b4' ,4, 't');
insert into test values( 'a2','b2' ,2, 't');
insert into test values( 'xx','xx' ,5, 'x');
insert into test values( 'a1','b1' ,1, 't');
insert into test values( 'a3','b3' ,3, 't');
insert into test values( 'a4','b4' ,4, 't');
insert into test values( 'a2','b2' ,2, 't');
insert into test values( 'xx','xx' ,5, 'x');
commit;
1.select a,b, sum(c) from test where d= 't' group by a,b order by a,b;
2.select a,b, sum(c) from test where d= 't' group by b,a order by a,b;
总结:对于1,2而言,结果应该是一样的,但是分组的顺序不同,sql的性能应该也是不同的。
复制代码 代码如下:
create table test(a varchar2( 20),b varchar2 (20),c number,d varchar2 (20))
insert into test values( 'a1','b1' ,1, 't');
insert into test values( 'a3','b3' ,3, 't');
insert into test values( 'a4','b4' ,4, 't');
insert into test values( 'a2','b2' ,2, 't');
insert into test values( 'xx','xx' ,5, 'x');
insert into test values( 'a1','b1' ,1, 't');
insert into test values( 'a3','b3' ,3, 't');
insert into test values( 'a4','b4' ,4, 't');
insert into test values( 'a2','b2' ,2, 't');
insert into test values( 'xx','xx' ,5, 'x');
commit;
1.select a,b, sum(c) from test where d= 't' group by a,b order by a,b;
2.select a,b, sum(c) from test where d= 't' group by b,a order by a,b;
总结:对于1,2而言,结果应该是一样的,但是分组的顺序不同,sql的性能应该也是不同的。