zoukankan      html  css  js  c++  java
  • SQL单表查询

    单表查询

    根据emp表来进行查询

    /*
    1. 查询出部门编号为30的所有员工*/
    select *
    from emp
    where deptno=30
    /*2. 所有销售员的姓名、编号和部门编号。*/
    select *
    from emp
    where job='销售员'
    /*3. 找出奖金高于工资的员工。*/
    select *
    from emp
    where sal<comm
    /*4. 找出奖金高于工资60%的员工。*/
    select *
    from emp
    where sal*0.6<comm
    /*5. 找出部门编号为10中所有经理,和部门编号为20中所有销售员的详细资料。*/
    select *
    from emp
    where (deptno=10 and job='经理') or (deptno=20 AND job='销售员')
    /*6. 找出部门编号为10中所有经理,部门编号为20中所有销售员,还有即不是经理又不是销售员但其工资大或等于20000的所有员工详细资料。*/
    select *
    from emp
    where (deptno=10 and job='经理') or (deptno=20 AND job='销售员') 
    or (job not in('经理','销售员') and sal>=20000)
    /*8. 无奖金或奖金低于1000的员工。*/
    select *
    from emp
    where comm is null or comm<1000
    /*9. 查询名字由三个字组成的员工。*/
    select *
    from emp
    where ename like '___'
    /*10.查询2000年入职的员工。*/
    select *
    from emp
    where hiredate like '2000-%'
    /*11. 查询所有员工详细信息,用编号升序排序*/
    select *
    from emp
    order by empno asc
    /*12. 查询所有员工详细信息,用工资降序排序,如果工资相同使用入职日期升序排序*/
    select *
    from emp
    order by sal desc,hiredate asc
    
    /*13. 查询每个部门的平均工资*/
    select deptno, avg(sal)
    from emp 
    group by deptno
    /*14. 查询每个部门的雇员数量。 */
    select deptno,count(*)
    from emp
    group by deptno
    /*15. 查询每种工作的最高工资、最低工资、人数*/
    select job,max(sal) '最高工资',min(sal) '最低工资',count(*) '人数'
    from emp
    group by job
  • 相关阅读:
    go excel导入Demo
    redis限流Lua脚本
    线上机器CPU与内存升高排查
    错点
    自动化运维工具——ansible详解(一)
    k8s之命令记录
    k8s之监控集群资源利用率
    根据经纬度搜索附近的人
    微信小程序直接打开h5页面
    【python3】字符串格式化
  • 原文地址:https://www.cnblogs.com/lxp503238/p/6964107.html
Copyright © 2011-2022 走看看