-
explain plan for select * from table; select * from table(dbms xplan.display);
查看全部 -
增删改查查看全部
-
group by~放在where后面,having是针对分组后的数据进行过滤,order by是放在整个语句的最后面查看全部
-
可以给聚合的列起别名,然后根据别名分组查看全部
-
order by 2 ~代表的是查询中的第二列查看全部
-
单行子查询和多行子查询
查看全部 -
按部门统计员工的人数:
函数查询:
select count(*) Total, sum(decode(to_char(hiredate,'YYYY'),'1980',1,0)) "1980", sum(decode(to_char(hiredate,'YYYY'),'1981',1,0)) "1981", sum(decode(to_char(hiredate,'YYYY'),'1982',1,0)) "1982", sum(decode(to_char(hiredate,'YYYY'),'1987',1,0)) "1987" from emp;
子查询:
select (select count(*) from emp) Total, (select count(*) from emp where to_char(hiredate,'YYYY')='1980') "1980", (select count(*) from emp where to_char(hiredate,'YYYY')='1981') "1981", (select count(*) from emp where to_char(hiredate,'YYYY')='1982') "1982", (select count(*) from emp where to_char(hiredate,'YYYY')='1987') "1987" from dual ;
查看全部 -
预学习查看全部
-
子查询注意点查看全部
-
子查询语法查看全部
-
create table pm_ci (ci_id varchar2(20) not null, stu_ids varchar2(100)); insert into pm_ci values('1','1,2,3,4'); insert into pm_ci values('2','1,4'); create table pm_stu (stu_id varchar2(20) not null, stu_name varchar2(20)); insert into pm_stu values('1','张三'); insert into pm_stu values('2','李四'); insert into pm_stu values('3','王五'); insert into pm_stu values('4','赵六'); select c.ci_id,wm_concat(s.stu_name) stu_name from pm_ci c,pm_stu s where instr(c.stu_ids,s.stu_id)>0 group by c.ci_id;查看全部
-
找到员工表中薪水大于本部门平均薪水的员工 select empno,ename,sal,(select avg(sal) from emp where deptno=e.deptno) avgsal from emp e where sal>(select avg(sal) from emp where deptno=e.deptno);查看全部
-
wm_concat查看全部
-
自连接存在的问题: 不适合操作大表 解决:层次查询 层次查询 某些情况下,可以代替自连接 本质上是一个单表查询 优点:不会产生笛卡尔集(单表查询) 缺点:查询结果不直观 select level,empno,ename,sal,mgr from emp connect by prior empno=mgr start with mgr is null order by 1; start with empno=7839 connect by 上一层的员工号=老板号查看全部
-
自连接:通过别名,将同一张表视为多张表 查询员工姓名和员工的老板姓名 select e.ename 员工姓名,b.ename 老板姓名 from emp e,emp b where e.mgr=b.empno;查看全部
举报