zoukankan      html  css  js  c++  java
  • Oracle数据库查询语句

    编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据:

    1.列出至少有一个员工的所有部门。

    SQL语句:

    select * from SCOTT.DEPT
    where deptno in
    (select distinct deptno from SCOTT.DEPT);

    查询结果:

    2.列出所有员工的姓名及其直接上级的姓名。

    SQL语句:

    select e.ename 员工姓名,m.ename 上级姓名
    from scott.emp e,scott.emp m
    where m.empno=e.mgr;

    查询结果:

    3.列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门。

    SQL语句:

    select d.dname,e.*
    from scott.dept d,scott.emp e
    where d.deptno=e.deptno(+);

    查询结果:

    4.列出最低薪金大于1500 的各种工作。

    SQL语句:

    select job 工作,min(sal) 最低薪金
    from SCOTT.EMP
    group by job
    having min(sal)>1500;

    查询结果:

    5.列出薪金高于公司平均薪金的所有员工。

    SQL语句:

    select *
    from SCOTT.EMP
    where  sal>(select avg(sal) from SCOTT.EMP);

    查询结果:

    6.列出薪金等于部门30 中员工的薪金的所有员工的姓名和薪金。

    SQL语句:

    select ename,sal,deptno
    from SCOTT.EMP
    where sal in (select sal from SCOTT.EMP where deptno=30);

    查询结果:

  • 相关阅读:
    iOS开发之窗口和视图
    GCD
    禁止非法用户登录综合设置
    大数减法(C++实现)
    大数加法(C++实现)
    迷宫问题 (BFS ➕输出路径)
    Pots (BFS ➕ 输出路径)
    Shuffle'm Up (map ➕ BFS)
    Prime Path (BFS)
    速算24点
  • 原文地址:https://www.cnblogs.com/shenxiaolin/p/5723893.html
Copyright © 2011-2022 走看看