zoukankan      html  css  js  c++  java
  • mysql练习

    1】查询所有雇员的雇员编号、雇员姓名、薪资、职位。

    select empno, ename, sal, job from emp;

    2】查询所有雇员的雇员编号、雇员姓名、年薪。

    select a.empno, a.ename, a.sal * 12, (b.sal + b.comm) * 12 from emp a

    left join emp b

    on a.empno = b.empno and b.comm is not null;

    3】列出emp表中所有的部门编号(dis)。

    select distinct deptno from emp;

    4】列出emp表中所有的职位及对应的部门编号。

    select distinct job, deptno from emp;

    5】查询所有薪资小于1200的雇员的信息。

    select * from emp where sal < '1200';

    6】查询薪资等于3000的雇员的信息。

    select * from emp where sal < '3000';

    7】查询雇员姓名叫“Smith”的信息。

    select * from emp where ename = 'smith';

    8】查询职位不是“办事员”并且薪资不小于2000的雇员的信息。

     select * from emp where job <> 'clerk' and sal <= 2000;

    9】查询工资在15003000之间的雇员的雇员编号、姓名、职位、薪资。

    select empno, ename, job, sal from emp where sal between 1500 and 3000;

    10】查询1981年雇佣的员工的信息。

    select * from emp where year(hiredate) = 1981;

    11】查询奖金部位空的雇员的信息(null)。

    select * from emp where comm is null;

    12】查询员工编号为“7369756677889999”的雇员的信息。

    select * from emp where empno in (7369, 7566, 7788, 9999);

    13】查询姓名以“A”开头的雇员的信息。

    select * from emp where ename like 'A%';

    14】查询姓名第二个字是“A”的雇员的信息。

    select * from emp where ename like '_A%';

    15】选择部门30中的所有员工

    select * from emp where deptno = 30;

    16】列出所有办事员的姓名、编号和部门编号

    select ename, empno, deptno from emp where job = 'clerk';

    17】找出佣金高于薪金的60%的员工

    select * from emp where comm > sal * 0.6 and comm is not null;

    18】找出部门10中所有经理MANAGER,部门20中所有办事员CLERK的详细资料

    select * from emp where (deptno = 10 and job = 'manager') or ( deptno = 20 and job = 'clerk');

    19】找出部门10中所有经理MANAGER,部门20中所有办事员CLERK,既不是经理又不是

    办事员但其薪金大于或等于2000的所有员工的详细资料。

    select * from emp where (deptno = 10 and job = 'manager') or (deptno = 20 and job = 'clerk') or (job not in ('clerk', 'manager') and sal > 2000);

    20】找出收取佣金的员工的职位、佣金。

    select job, comm from emp where comm is not null;

    21】找出不收取佣金或收取的佣金低于100的员工的信息。

    select * from emp where comm is null or comm is not null and comm < 100;

    22】显示姓名中不带有“r”的员工的姓名

    select ename from emp where ename not like '%r%';

    23】显示姓名字段的任何位置包含“A”的所有员工的姓名,显示的结果按照基本工资由高到低排序,如果基本工资相同则按照雇佣年限由早到晚排序,如果雇佣日期相同,则按照职位排序。

    select ename from emp where ename like '%A%' order by sal desc, hiredate desc, job desc; 

  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/assassin3154/p/7840914.html
Copyright © 2011-2022 走看看