网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 交易代码 > SQL语法 > 正文

03SQL基本查询语句作业(答案)

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

【网学网提醒】:网学会员编辑为广大网友搜集整理了:03SQL基本查询语句作业(答案)绩等信息,祝愿广大网友取得需要的信息,参考学习。


    作业一、复习课上讲的知识,完成以下简单的查询语句操作:二、1、显示emp表的结构desc表名2、查询emp表所有列select*fromemp;3、查询emp中的雇员指定列Selectenamefromemp;4、如何取消重复行:查询有哪些部门,哪些工作selectdistinctdeptno,jobfromemp;5、使用算术表达式:如何计算每个雇员的年工资,nvl(comm,0):是oracle自己的一个函数如果没有奖金给0如果有奖金,就给commselectename,sal*12+nvl(comm,0)*12年工资fromemp;6、使用列的别名:显示年工资大于20000的所有员工selectename,sal*12+nvl(comm,0)*12sal*12+nvl(comm,0)*12>200007、如何处理null值,请用例子说明nvl(comm,0):是oracle自己的一个函数如果没有奖金给0如果有奖金,就给comm8、使用where子句8.1)在where条件中使用数字:如何显示工资高于3000的员工selectename,salfromempwheresal>3000;8.2)在where条件中使用字符值:如何显示为JONES的员工信息Select*fromempwhereename=’JONES’注意:1.要用单引号引住2.区分大小写8.3)在where条件中使用日期值:请问如何查找1982.1.1后入职的员工注意:1.要有单引号引住2.要符合日期的形式否则要出错select*fromempwherehiredate>'1-1月-82';8.4)在where条件中使用between...and:请问:如何显示工资在2000到2500的员工情况fromempwhere
    select*fromempwheresalbetween2000and2500;
     8.5)在where条件中如何使用like操作符(模糊查询)%:表示0到多个字符_:表示任意一个字符如何显示首字符为S的员工和工资如何显示第三个字符为大写O的所有员工的和工资Selectename,salfromempwhereenamelike‘S%’selectename,salfromempwhereenamelike'__O%'8.6)在where条件中使用in:如何显示empno为123,345,800,1250...的雇员情况select*fromempwhereempnoin(123,345,800,1250)8.7)在where条件中使用isnull的操作符:select*fromempwheremgrisnull;8.8)在where条件中使用逻辑操作符号and,or如何查询工资高于2500或是岗位为MANAGER的雇员,同时还要满足他们的首写字母为大写的Jselect*fromempwhereenamelike'J%'and(sal>2500orjob='MANAGER')9、使用orderby字句当执行查询操作时,默认情况下会按照行数据插入的先后顺序来显示数据.但是在实际的应用中常常需要对数据进行排序,可以使用orderby注意:在select语句中可以包含多个子句(where,groupby,having,orderby)但是orderby必须是最后一个子句9.1)升序排列:如何按照工资的从低到高或从高到低的顺序显示雇员的信息select*fromemporderbysal;//从高到低(desc从高到低asc低到高)select*fromemporderbysaldesc;9.2)使用多列排序:如何按照部门号升
    序而雇员的工资降序排列select*fromemporderbydeptno,saldesc;9.3)使用列的别名排序,如果在where子句中为列或是表达式定义了别名,那么当执行排序操作时,即可以使用列或是表达式排序,也可使用列别名排序如何按照年薪从低到高排序?Select*fromemporderbysal*129.4)使用列的编号进行排序
    selectempno,deptno,enamefromemporderby1asc,2desc;
    请思考:如何显示没有上级的雇员的情况
    10、查询表中限定位置记录
    按雇员的id号升序取出
     1)返回前5行数据2)返回6到10行数据3)返回最后5行数据1)select*fromempwhererownum<=52)select*from(selectrownumrn,empno,enamefromempwhererownum<=10)temp
    wheretemp.rn>=6
    3)select*from(selectrownumrn,empno,enamefromempwhererownum<15)temp
    wheretemp.rn>10
    三、使用scott/tiger用户下的emp表完成下列练习:emp员工表的表结构及数据类型说明如下:
    1.选择部门30中的所有员工.select*fromempwheredeptno=302.列出所有办事员(CLERK)的,编号和部门编号.selectename,empno,deptnofromempwherejob='CLERK';能用单引号*/3.找出佣金高于薪金的员工.select*fromempwherenvl(comm,0)>sal;select*fromempwherecomm>sal;比较忽略comm为空的值nvl(col1,p)要求col1和p的类型是一致的4.找出佣金高于薪金的60%的员工.select*fromempwherenvl(comm,0)>sal*0.6;5.找出部门10中所有经理(MANAGER)和部门20中所有办事员(CLERK)的详细资料./*注意大小写要完全匹配,且只
     select*fromempwheredeptnoin(10,20)select*fromempwhere(deptno=10andjob='MANAGER')or(deptno=20andjob='CLERK')6.找出部门10中所有经理(MANAGER),部门20中所有办事员(CLERK),既不是经理又不是办事员但其薪金大于或等于2000的所有员工的详细资料.select*fromempwhere(deptno=10andjob='MANAGER')or(deptno=20andjob='CLERK')or(jobnotin('MANAGER','CLERK')andsal>=2000)或者用:
    select*fromempwhere(deptno=10andjob='MANAGER')or(deptno=20andjob='CLERK')or(job<>'MANAGER'andjob<>'CLERK'andsal>=2000)
    7.找出收取佣金的员工的不同工作.selectdistinctjobfromempwherenvl(comm,0)>0;8.找出不收取佣金或收取的佣金低于100的员工的资料.select*fromempwherenvl(comm,0)<100orcommisnull;
    select*fromempwherecomm<100orcommisnull;select*fromempwherenvl(comm,0)<100;select*fromempwherecomm<100;这句不对
    9.找出各月倒数第3天受雇的所有员工.last_day(日期类型)所在月的最后一天select*fromempwherehiredate=last_day(hiredate)-2;哑元表dual:当不需要表的地方可以考虑使用它
    select1+1fromdualselectto_char(sysdate,'yyyy-mm-ddhh24:mi:ss')fromdualselect'helloworld'ashwfromdual
    10.找出早于12年前受雇的员工.select*fromempwherehir
    edate    select*fromempwheremonths_between(sysdate,hiredate)>144
    add_months(sysdate,-12*12)返回日期类型11.以首字母大写的方式显示所有员工的.
    selectinitcap(ename)asfromemp;
    12.显示正好为5个字符的员工的.selectenamefromempwhereenamelike'_____';
    selectenamefromempwherelength(ename)=5
    like中_表示一个字符%任意个字符13.显示不带有"R"的员工的.
     selectenamefromempwhereenamenotlike'%R%';
    selectenamefromempwhereinstr(ename,'R')=0
    14.显示所有员工的前三个字符.selectsubstr(ename,1,3)fromemp;substr(字符,位置开始,位置结束)selectename,substr(ename,4)asename1fromemp;从第四个位置开始取15.显示所有员工的,用a替换所有"A"selecttranslate(ename,'A','a')fromemp;16.显示满10年服务年限的员工的和受雇日期.selectename,hiredatefromempwheresysdate>add_months(hiredate,12*10);months_between(sysdate,hiredate)两个日期之间的月数sysdate-hiredate天数selectename,hiredatefromempwheremonths_between(sysdate,hiredate)>120;
    selectename,hiredatefromempwheremonths_between(hiredate,sysdate)<-120;
    17.显示员工的详细资料,按排序.select*fromemporderbyename;select*fromemporderbyenamedesc;18.显示员工的和受雇日期,根据其服务年限,将最老的员工排在最前面.selectename,hiredatefromemporderbyhiredate;19.显示所有员工的、工作和薪金,按工作的降序排序,若工作相同则按薪金排序.selectename,job,salfromemporderbyjobdesc,sal;20.显示所有员工的、加入公司的年份和月份,按受雇日期所在月排序若月份相同则将最早年份的员工排在最前面.
    selectename,to_char(Hiredate,'yyyy"?ê"mm"??"')as?ê??,hiredatefromemporderbyto_char(Hiredate,'mm'),to_char(Hiredate,'yyyy');
    21.显示今天是今年第几天,当月第几天,第几月
    selectto_char(sysdate,'day')fromdual;
    selectto_char(sysdate,'ddd')fromdual;
    显示今年的第几天
     selectto_char(sysdate,'dd')fromdual;
    显示当月的第几天
    selectto_char(sysdate,'mm')fromdual;
    显示第几月
    selectto_char(sysdate,'month')fromdual;
    selectto_char(sysdate,'yyyy')fromdual;
    selectto_char(sysdate,'hh24:mi:ss')fromdual;
    22.显示在一个月为30天的情况所有员工的日薪金,忽略余数.selectround(sal/30)fromemp;忽略余数/截断trunc()
    selecttrunc(17.25)fromdualselecttrunc(17.89)fromdualselecttrunc(17.25,1)fromdual四舍五入round()selectround(17.25)fromdualselectround(17.25,1)fromdual显示17显示17.3显示17显示17显示17.2
    23.找出在(任何年份的)2月受聘的所有员工。select*fromempwherehiredatelike'%-2月%';
    select*fromempwhereto_char(hiredate,'mm')='02';
    24.显示字段的任何位置包含"A"的所有员工
    的.selectenamefromempwhereenamelike'%A%';
    select*fromempwhereinstr(ename,'A')>0;
    
    
  • 上一篇资讯: 03SQL基本查询语句作业
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师