1.自己构造两条不同的SQL来完成相同的查询,注意结果集重用对SQL性能的影响
四个主人公:alan leonarding sun xy
故事:这4个小伙伴刚刚毕业,毕业后都顺利的找到了工作,现在已经工作半年了,一次他们聚在了一起,由于虚荣心的驱动他们想比一比谁的工资攒的多,大家都是学IT出身,于是他们做了一个leo_salary表来计算他们这半年来的平均工资!
创建了leo_salary表,雇员id 名/字 薪水 月份
LS@LEO> create table leo_salary (employee_id number,name varchar(20),salary number,month date);
Table created.
LS@LEO> insert into leo_salary values (1,'alan',1000,to_date('2012_01_01','yyyy-mm-dd')); alan同学工资
insert into leo_salary values (1,'alan',1100,to_date('2012_02_01','yyyy-mm-dd'));
insert into leo_salary values (1,'alan',1200,to_date('2012_03_01','yyyy-mm-dd'));
insert into leo_salary values (1,'alan',1300,to_date('2012_04_01','yyyy-mm-dd'));
insert into leo_salary values (1,'alan',1400,to_date('2012_05_01','yyyy-mm-dd'));
insert into leo_salary values (1,'alan',1500,to_date('2012_06_01','yyyy-mm-dd'));
insert into leo_salary values (2,'leonarding',200,to_date('2012_01_01','yyyy-mm-dd')); leonarding同学工资
insert into leo_salary values (2,'leonarding',210,to_date('2012_02_01','yyyy-mm-dd'));
insert into leo_salary values (2,'leonarding',220,to_date('2012_03_01','yyyy-mm-dd'));
insert into leo_salary values (2,'leonarding',230,to_date('2012_04_01','yyyy-mm-dd'));
insert into leo_salary values (2,'leonarding',240,to_date('2012_05_01','yyyy-mm-dd'));
insert into leo_salary values (2,'leonarding',250,to_date('2012_06_01','yyyy-mm-dd'));
insert into leo_salary values (3,'sun',400,to_date('2012_01_01','yyyy-mm-dd')); sun同学工资
insert into leo_salary values (3,'sun',410,to_date('2012_02_01','yyyy-mm-dd'));
insert into leo_salary values (3,'sun',420,to_date('2012_03_01','yyyy-mm-dd'));
insert into leo_salary values (3,'sun',430,to_date('2012_04_01','yyyy-mm-dd'));
insert into leo_salary values (3,'sun',440,to_date('2012_05_01','yyyy-mm-dd'));
insert into leo_salary values (3,'sun',450,to_date('2012_06_01','yyyy-mm-dd'));
insert into leo_salary values (4,'xy',600,to_date('2012_01_01','yyyy-mm-dd')); xy同学工资
insert into leo_salary values (4,'xy',610,to_date('2012_02_01','yyyy-mm-dd'));
insert into leo_salary values (4,'xy',620,to_date('2012_03_01','yyyy-mm-dd'));
insert into leo_salary values (4,'xy',630,to_date('2012_04_01','yyyy-mm-dd'));
insert into leo_salary values (4,'xy',640,to_date('2012_05_01','yyyy-mm-dd'));
insert into leo_salary values (4,'xy',650,to_date('2012_06_01','yyyy-mm-dd'));
commit;
LS@LEO> select count(*) from leo_salary;
COUNT(*)
----------
24
LS@LEO> select * from leo_salary;
EMPLOYEE_ID NAME SALARY MONTH
----------- -------------------- ---------- -------------------
1 alan 1000 2012-01-01 00:00:00
1 alan 1100 2012-02-01 00:00:00