/* 2 功能:生成博客目录的JS工具 3 测试:IE8,火狐,google测试通过 6 */ 7 var BlogDirectory = { 8 /* 9 获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top) 10 */ 11 getElementPosition:function (ele) { 12 var topPosition = 0; 13 var leftPosition = 0; 14 while (ele){ 15 topPosition += ele.offsetTop; 16 leftPosition += ele.offsetLeft; 17 ele = ele.offsetParent; 18 } 19 return {top:topPosition, left:leftPosition}; 20 }, 21 22 /* 23 获取滚动条当前位置 24 */ 25 getScrollBarPosition:function () { 26 var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop; 27 return scrollBarPosition; 28 }, 29 30 /* 31 移动滚动条,finalPos 为目的位置,internal 为移动速度 32 */ 33 moveScrollBar:function(finalpos, interval) { 34 35 //若不支持此方法,则退出 36 if(!window.scrollTo) { 37 return false; 38 } 39 40 //窗体滚动时,禁用鼠标滚轮 41 window.onmousewheel = function(){ 42 return false; 43 }; 44 45 //清除计时 46 if (document.body.movement) { 47 clearTimeout(document.body.movement); 48 } 49 50 var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置 51 52 var dist = 0; 53 if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出 54 window.onmousewheel = function(){ 55 return true; 56 } 57 return true; 58 } 59 if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离 60 dist = Math.ceil((finalpos - currentpos)/10); 61 currentpos += dist; 62 } 63 if (currentpos > finalpos) { 64 dist = Math.ceil((currentpos - finalpos)/10); 65 currentpos -= dist; 66 } 67 68 var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置 69 window.scrollTo(0, currentpos);//移动窗口 70 if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出 71 { 72 window.onmousewheel = function(){ 73 return true; 74 } 75 return true; 76 } 77 78 //进行下一步移动 79 var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")"; 80 document.body.movement = setTimeout(repeat, interval); 81 }, 82 83 htmlDecode:function (text){ 84 var temp = document.createElement("div"); 85 temp.innerHTML = text; 86 var output = temp.innerText || temp.textContent; 87 temp = null; 88 return output; 89 }, 90 91 /* 92 创建博客目录, 93 id表示包含博文正文的 div 容器的 id, 94 mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!), 95 interval 表示移动的速度 96 */ 97 createBlogDirectory:function (id, mt, st, interval){ 98 //获取博文正文div容器 99 var elem = document.getElementById(id); 100 if(!elem) return false; 101 //获取div中所有元素结点 102 var nodes = elem.getElementsByTagName("*"); 103 //创建博客目录的div容器 104 var divSideBar = document.createElement('DIV'); 105 divSideBar.className = 'sideBar'; 106 divSideBar.setAttribute('id', 'sideBar'); 107 var divSideBarTab = document.createElement('DIV'); 108 divSideBarTab.setAttribute('id', 'sideBarTab'); 109 divSideBar.appendChild(divSideBarTab); 110 var h2 = document.createElement('H2'); 111 divSideBarTab.appendChild(h2); 112 var txt = document.createTextNode('目录导航'); 113 h2.appendChild(txt); 114 var divSideBarContents = document.createElement('DIV'); 115 divSideBarContents.style.display = 'none'; 116 divSideBarContents.setAttribute('id', 'sideBarContents'); 117 divSideBar.appendChild(divSideBarContents); 118 //创建自定义列表 119 var dlist = document.createElement("dl"); 120 divSideBarContents.appendChild(dlist); 121 var num = 0;//统计找到的mt和st 122 mt = mt.toUpperCase();//转化成大写 123 st = st.toUpperCase();//转化成大写 124 //遍历所有元素结点 125 for(var i=0; i

oracle学习笔记(十二) 查询练习(二) 高级查询

高级查询练习

/*--------------------------------------------- 分组查询 -------------------------------------*/
create table empployee_demo(
   empno     number(4) not null primary key,  --员工编号,主键
   ename     varchar2(10) not null unique,    --员工名,唯一键
   job       varchar2(9),                     --职位、工作
   mgr       number(4),                       --经理编号
   hiredate  date default sysdate,            --入职日期,默认约束
   sal       number(7,2) check(sal>=500 and sal<=10000),   --工资
   comm      number(7,2),                     --资金
   deptno    number(2)                        --部门编号
)
--28.按各部门的'办事员'分别统计薪资情况,且平均大于1000的

select deptno,avg(sal) avgsal from employee
where job ='CLERK'
group by deptno
having avg(sal)>1000 

--29. 显示非销售人员工作名称以及从事同一工作雇员的月工资的总和,
--并且要满足从事同一工作的雇员的月工资合计大于$5000,输出结果按月工资排序。
select sal from employee
where job !='saleman'
group by job
having sum(sal) >5000
order by sal;
--30. 查询出各部门的部门编号以及各部门的总工资和平均工资。
select deptno,sum(sal),avg(sal) from employee
group by deptno

--31. 按男生和女生统计JAVA和ORACLE成绩的总分和平均分?
--  1)  建表
CREATE table STUDENT2(
  STUNO       CHAR(4) not null primary KEY,
  STUNAME     VARCHAR2(20),
  GENDER      CHAR(2),
  JAVASCORE   INTEGER,
  ORACLESCORE INTEGER
);
--  2)  插入记录
INSERT INTO STUDENT2 VALUES('1000','JAMES','男',88,78);
INSERT INTO STUDENT2 VALUES('1001','JACK','男',86,79);
INSERT INTO STUDENT2 VALUES('1002','ANDY','女',76,78);
INSERT INTO STUDENT2 VALUES('1003','SAMMY','女',77,76);

--  3)按性别统计成绩:平均分,总成绩等

select avg(javascore),avg(oraclescore),gender from student2
group by gender
----高级查询---
--创表
create table employee as select * from scott.emp;
create table department as select * from scott.dept;
create table salgrade as select * from scott.salgrade;

--employee表结构
EMPNO    NUMBER(4)                              
ENAME    VARCHAR2(10) Y                         
JOB      VARCHAR2(9)  Y                         
MGR      NUMBER(4)    Y                         
HIREDATE DATE         Y                         
SAL      NUMBER(7,2)  Y                         
COMM     NUMBER(7,2)  Y                         
DEPTNO   NUMBER(2)    Y

--deparment表结构
DEPTNO NUMBER(2)                              
DNAME  VARCHAR2(14) Y                         
LOC    VARCHAR2(13) Y 

--salgrade表结构
GRADE NUMBER Y                         
LOSAL NUMBER Y                         
HISAL NUMBER Y  


--32. 查询部门在‘NEW YORK’工资低于4000,不是‘CLERK’的员工?
select * from employee e
    left join department d
        on e.deptno = d.deptno
where sal<4000 and job != 'CLERK' and loc ='NEW YORK'

--33. 查询部门在‘CHICAGO’,在1981年入职,工资在2000~4000的员工?
select * from employee e
    left join department d
        on e.deptno = d.deptno
where sal between 2000 in 4000 and loc = 'CHICAGO' and extract( year from hiredate) = 1981

--34:查询员工及所在的部门信息(部门号,部门名,所在城市)
select ename,e.deptno,dname,loc from employee e
    left join department d on e.deptno = d.deptno;
    
--35:查询在10号部门号的员工及部门信息(部门号,部门名,所在城市)
select ename,e.deptno,dname,loc from employee e
    left join department d on e.deptno = d.deptno
where e.deptno = 10
--36:查询工资低于3000,工作是clerk和salman,部门在"芝加哥”的员工基本信息和员工的部门信息。
select e.*,,d.dname,d.loc
    from employee e
    left join department d on e.deptno = d.deptno
where sal <3000 and (job ='CLERK' or job = 'SALMAN') and loc ='CHICAGO'

/*
37: 问题:查看每个员工的工资等级情况
    1等级-->显示为:临时工
    2等级-->显示为:苦力工
    3等级-->??
*/
select e.*,decode(grade,1,'苦力',2,'临时工','其他')from employee e,salgrade
where sal between losal and hisal

-- 38.查询有上级领导的员工信息以及他的上级领导的信息。显示为:谁(工人)为谁(上级)工作
select e.name 员工,boss.name 上司 from employee e,employee boss
where e.mgr = boss.empno
posted @ 2019-09-19 14:36  我的人生  阅读(318)  评论(0)    收藏  举报