• myonepractice


    select * from EMP where ENAME ='SMITH';
    select ename || ' is a ' || job from emp;
    select distinct empno from emp;
    select * from emp where COMM>SAL;
    select COMM+SAL from emp;
    select * from emp where job not in('SALESMAN','MANAGER');
    select * from emp where COMM is not null;
    select ename,sal from emp order by sal; /*默认升序(asc)*/
    select upper ('avdd') from dual;
    select initcap(ename) from emp;/*将所有单词首字母变大写*/
    select concat('s','v')from dual;
    select concat('a','') from dual;
    select concat('','a') from dual;/*对空格连接不起作用*/
    select length(ename) from emp;/*测量某列长度*/
    select replace('ename','a','K') from dual;
    select instr('hello world','e')from dual;/*指定字符出现的位置*/
    select concat(JOB,SAL) from emp;
    select JOB||SAL from emp;
    select * from emp where lower(ENAME)='smith';
    select * from emp where ENAME is null;
    select length(ename) from emp;/*列的真实字段名儿*/
    /*substr(字符串,截取开始位置,截取长度) //返回截取的字*/
    select trunc(49.736,-1) from dual;
    select sysdate from dual;
    select months_between(to_date('10-07-1994','dd-mm-yyyy'),to_date('11-06-1994','dd-mm-yyyy')) from dual;
    select add_months(to_date('08-03-2017','dd-mm-yyyy'),6) from dual;
    select '['||ENAME||']' from emp;
    select '['||ENAME||']' from emp where ename='SMITH';
    select NEXT_DAY(to_date('01-09-2017','dd-mm-yyyy'),'星期一') from dual;
    select last_day(to_date('18-08-2017','dd-mm-yyyy')) from dual;
    select to_char(sysdate,'mm') from dual;
    select to_number('13')+to_number('15')from dual;--转换为数字
    select round(to_date('08-09-2013','dd-mm-yyyy')) from dual;
    select round(sysdate) from dual;
    --分组函数
    select avg(sal) from emp;
    select sum(sal) from emp;
    select max(sal) from emp;
    select min(sal) from emp;
    --4.6
    select *from emp where last_day(HIREDATE)-2=HIREDATE;
    select * from emp where hiredate<=add_months(hiredate,-25*12);--25年前雇的员工
    select round(months_between(sysdate,HIREDATE))*30 from emp;
    --通用函数
    select nvl(COMM,0) from emp;--相同则返回空值,不相同则返回第一个表达式的值
    select nvl2(sal,comm+sal,sal) from emp;--第一个值不为空,则返回第二个值;为空则返回第三个值
    select sal,coalesce(sal,COMM+SAL,sal,0) from emp;--返回第一个非空值
    select empno case deptno 
                      when 10 then '财务部'
                      when 20 then '研发部'
                      else '销售部'
                      end 
                      from emp;
    --分组函数
    select ename from emp group by DEPTNO,ename;
    select avg(sal),deptno from emp group by deptno;
    select count(*) from emp;
    select avg(sal) from emp group by sal order by sal desc;--order by出现在group by之前没有意义
    select * from emp;
    select sal,deptno from emp group by sal,deptno;
    --多表查询
    select * from STUDENT,SC;
    select * from(select * from sc,student where student.s#=sc.s#) as a group by a.c#;--false
    select student.s#,student.* from student left outer join sc on sc.s#=student.s#;
    select /*s#,sname,*/avg(select score from
                                   (select student.s#,student.sname,sc.score from student,sc where student.s#=sc.s#(+))xinbiao)
                                   from xinbiao
                                   group by xinbiao.score;--感觉快要成功了,加油啊!!!
    select count(*) from(select student.s#,student.sage,sc.score from student,sc where student.s#=sc.s#(+)); 
    select student.s#,student.sname,avg(sc.score)from student,sc where student.s#(+)=sc.s# group by sc.score;
    --practice
    select emp.deptno,count(*)from emp group by emp.deptno;
    select avg(sal)/*,emp.deptno*/from emp where sal>500 group by emp.deptno /*having sal>500*/
    --查询显示工资大于各个部门工资的平均值的员工信息
    select * from emp e1,(select avg(sal) avgsal from emp)e2 where e1.sal>e2.avgsal; 
    select avg(sal),deptno from emp group by deptno having sal>avg(sal);
    select count(*),emp.deptno from emp group by emp.deptno;
    --查询出每个部门的编号、名称、位置、部门人数、平均工资
    select emp.deptno,emp.ename,emp.mgr from emp;
    select avg(sal) from emp group by emp.deptno;
    --要求查询出工资比SMITH工资要高的全部雇员信息
    select * from emp where sal>(select sal from emp where emp.ename='SMITH');
    select * from emp where sal>800;
    select* from emp where sal between 0 and 1000;
    select emp.sal from emp order by sal desc;
    select sal*12 as a from emp;  
    select * from emp where job not in('CLERK');
    select * from emp where job not LIKE('%CLERK%');
    select * from emp where emp.ename like('%O%T%');
    select distinct emp.job from emp;
    --查询平均成绩大于等于70分的同学的学生编号和学生姓名和平均成绩
    select student.s#,student.sname from student,(select avg(sc.score)avgsr from sc group by sc.c#)avgsc where avgsc.avgsr>=70;
  • 相关阅读:
    Android学习之多线程开发总结<二>
    Android学习之多线程开发总结<一>
    Android代码模版整理<一>
    Android学习之Bluetooth开发总结<续3>
    Android学习—自定义组件
    Android学习之解析XML
    Android学习—自定义对话框Dialog
    Android学习之Bluetooth开发总结<续2>
    Android学习之Bluetooth开发总结<续>
    .Net Core 发布项目时出现警告提示“不建议指定此包的版本”的解决办法
  • 原文地址:https://www.cnblogs.com/kiskistian/p/7193652.html
Copyright © 2020-2023  润新知