w3resource_MySQL练习题:Aggregate_functions
 
1. Write a query to list the number of jobs available in the employees table
Sample table: employees
  1. -- 要点:count() + distinct
  2. select count(distinct job_id)
  3. from employees
2. Write a query to get the total salaries payable to employees
Sample table: employees
  1. -- 要点:sum()
  2. select sum(salary)
  3. from employees
 
3. Write a query to get the minimum salary from employees table
Sample table: employees
  1. -- 要点:min()
  2. select min(salary)
  3. from employees
4. Write a query to get the maximum salary of an employee working as a Programmer
Sample table: employees
  1. -- 要点:max()
  2. select max(salary)
  3. from employees
  4. where job_id = 'IT_PROG'

  

5. Write a query to get the average salary and number of employees working the department 90
Sample table: employees
  1. -- 要点:avg() + count()
  2. select avg(salary), count(*)
  3. from employees
  4. where department_id=90
6. Write a query to get the highest, lowest, sum, and average salary of all employees
Sample table: employees
  1. -- 要点:max() + min() + sum() + avg()
  2. select max(salary), min(salary), sum(salary), avg(salary)

  

7. Write a query to get the number of employees with the same job
Sample table: employees
  1. -- 要点:group by进行分组
  2. select job_id, count(*)
  3. from employees
  4. group by job_id
8. Write a query to get the difference between the highest and lowest salaries
Sample table: employees
  1. -- 要点:max() + min()
  2. select max(salary)-min(salary)
  3. from employees

  

9. Write a query to find the manager ID and the salary of the lowest-paid employee for that manager
Sample table: employees
  1. -- 要点:根据manager_id进行分组,得到每个分组内最低的salary(min)
  2. select manager_id, min(salary)
  3. from employees
  4. group by manager_id

  

10. Write a query to get the department ID and the total salary payable in each department
Sample table: employees
  1. -- 要点:根据department_id进行分组,得到每个分组内salary总和(sum)
  2. select department_id, sum(salary)
  3. from employees
  4. group by department_id

  

11. Write a query to get the average salary for each job ID excluding programmer
Sample table: employees
  1. -- 要点:通过job_id进行分组,得到每个分组内平均的salary(avg),
  2. select job_id, avg(salary)
  3. from employees
  4. where job_id<>'IT_PROG'
  5. group by job_id

  

12. Write a query to get the total salary, maximum, minimum, average salary of employees (job ID wise), for department ID 90 only
Sample table: employees
  1. -- 要点:同上,通过job_id进行分组,得到每个组内相应数值,并且使用where进行department_id筛选
  2. select job_id, sum(salary), max(salary), min(salary), avg(salary)
  3. from employees
  4. where department_id=90
  5. group by job_id
13. Write a query to get the job ID and maximum salary of the employees where maximum salary is greater than or equal to $4000
Sample table: employees
  1. -- 要点:分组后的条件限制,使用having
  2. select job_id, max(salary)
  3. from employees
  4. group by job_id
  5. having max(salary)>=4000

  

14. Write a query to get the average salary for all departments employing more than 10 employees
Sample table: employees
  1. -- 要点:同上,分组后使用having
  2. select department_id, avg(salary)
  3. from employees
  4. group by department_id
  5. having count(salary)>10

  

w3resource_MySQL练习: Aggregate_functions的更多相关文章

  1. w3resource_MySQL练习:Joins

    w3resource_MySQL练习题:Joins 1. Write a query to find the addresses (location_id, street_address, city, ...

  2. w3resource_MySQL练习:Subquery

    w3resource_MySQL练习题:Subquery 1. Write a query to find the name (first_name, last_name) and the salar ...

  3. w3resource_MySQL练习:Basic_select_statement

    w3resource_MySQL练习题:Basic_select_statement 1. Write a query to display the names (first_name, last_n ...

  4. CentOS7安装性能监控系统

    目录 系统描述. 开发环境. 开始之前. 安装influxdb数据库. 安装collectd 安装Grafana FAQ       influxdb的web界面没反应.   系统描述 想打造 New ...

  5. ClickHouse源码笔记2:聚合流程的实现

    上篇笔记讲到了聚合函数的实现并且带大家看了聚合函数是如何注册到ClickHouse之中的并被调用使用的.这篇笔记,笔者会续上上篇的内容,将剖析一把ClickHouse聚合流程的整体实现. 第二篇文章, ...

  6. Mybatis分页插件: pageHelper的使用及其原理解析

    在实际工作中,很进行列表查询的场景,我们往往都需要做两个步骤:1. 查询所需页数对应数据:2. 统计符合条件的数据总数:而这,又会导致我们必然至少要写2个sql进行操作.这无形中增加了我们的工作量,另 ...

  7. ClickHouse源码笔记5:聚合函数的源码再梳理

    笔者在源码笔记1之中分析过ClickHouse的聚合函数的实现,但是对于各个接口函数的实际如何共同工作的源码,回头看并没有那么明晰,主要原因是没有结合Aggregator的类来一起分析聚合函数的是如果 ...

随机推荐

  1. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

    Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...

  2. 详解window.history

    http://blog.csdn.net/woxueliuyun/article/details/51075272

  3. CSS——制作天天生鲜主页

    终于做好了! index.html: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  4. PIX 防火墙

    ---恢复内容开始--- 一 , PIX 防火墙的认识 PIX 是cisco 的硬件防火墙 硬件防火墙的工作速度快,使用方便. PIX 有很多型号,并发连接数是PIX防火墙的重要参数   PIX 25 ...

  5. HttpHelper使用记录

    重新载入页面以获取源代码 var item = new HttpItem() { URL = @"http://www.xxx.com/msg/basic/?a=sendmsg", ...

  6. 《springcloud 二》SrpingCloud Zuul 微服务网关搭建

    网关作用 网关的作用,可以实现负载均衡.路由转发.日志.权限控制.监控等. 网关与过滤器区别 网关是拦截所有服务器请求进行控制 过滤器拦截某单个服务器请求进行控制 Nginx与Zuul的区别 Ngin ...

  7. [转]eclipse启动tomcat无法访问的解决方法

    这篇文章介绍了eclipse启动tomcat无法访问的解决方法,有需要的朋友可以参考一下 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080 ...

  8. Java获取服务器系统默认编码格式

    大佬教的,做个笔记方法一(推荐):新建一个jsp页面在webapp下然后添加 <% out.print(System.getProperties().getProperty("file ...

  9. IO流----File,递归,字节流,字符流

    要把数据持久化存储,就需要把内存中的数据存储到内存以外的其他持久化设备(硬盘.光盘.U盘等)上. 当需要把内存中的数据存储到持久化设备上这个动作称为输出(写)Output操作. 当把持久设备上的数据读 ...

  10. Git中文件属性的变化,被认为是文件有改动

    问题描述: 1.  从公司的git服务器上, 下载最新的代码(zip格式), 解压缩出来, 2.  过一段时间, 去执行git pull代码, 出现如下情况: $ git pull Updating ...