w3resource_MySQL练习题:Aggregate_functions
 
1. Write a query to list the number of jobs available in the employees table
Sample table: employees
-- 要点:count() + distinct
select count(distinct job_id)
from employees
2. Write a query to get the total salaries payable to employees
Sample table: employees
-- 要点:sum()
select sum(salary)
from employees
 
3. Write a query to get the minimum salary from employees table
Sample table: employees
-- 要点:min()
select min(salary)
from employees
4. Write a query to get the maximum salary of an employee working as a Programmer
Sample table: employees
-- 要点:max()
select max(salary)
from employees
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
-- 要点:avg() + count()
select avg(salary), count(*)
from employees
where department_id=90
6. Write a query to get the highest, lowest, sum, and average salary of all employees
Sample table: employees
-- 要点:max() + min() + sum() + avg()
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
-- 要点:group by进行分组
select job_id, count(*)
from employees
group by job_id
8. Write a query to get the difference between the highest and lowest salaries
Sample table: employees
-- 要点:max() + min()
select max(salary)-min(salary)
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
-- 要点:根据manager_id进行分组,得到每个分组内最低的salary(min)
select manager_id, min(salary)
from employees
group by manager_id

  

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

  

11. Write a query to get the average salary for each job ID excluding programmer
Sample table: employees
-- 要点:通过job_id进行分组,得到每个分组内平均的salary(avg),
select job_id, avg(salary)
from employees
where job_id<>'IT_PROG'
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
-- 要点:同上,通过job_id进行分组,得到每个组内相应数值,并且使用where进行department_id筛选
select job_id, sum(salary), max(salary), min(salary), avg(salary)
from employees
where department_id=90
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
-- 要点:分组后的条件限制,使用having
select job_id, max(salary)
from employees
group by job_id
having max(salary)>=4000

  

14. Write a query to get the average salary for all departments employing more than 10 employees
Sample table: employees
-- 要点:同上,分组后使用having
select department_id, avg(salary)
from employees
group by department_id
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. centos6.3搭建FTP服务器图文教程

    今天下午不忙,没什么事,看到我大红盟linux版块如此冷清,心不能忍,做了个FTP服务器的搭建教程,大家可以看看, 不会做视频,就图文交叉了,写得不好,望谅解.以后有时间再出一个LNMP的教程. 不磨 ...

  2. readonly与const的区别

    readonly 关键字与 const 关键字不同.const 字段只能在该字段的声明中初始化.readonly字段可以在声明或构造函数中初始化.因此,根据所使用的构造函数,readonly字段可能具 ...

  3. Rest_framework之版本控制、响应器和分页器

    一.访问频率补充 频率: 自定义: 1 定义一个类MyThrottles allow_request(频率限制的逻辑) ==>这两个函数都是派生出来的,继承的类里面封装的. wait(返回一个数 ...

  4. mui轮播图

    轮播组件是mui提供的一个核心组件,在该核心组件基础上,衍生出了图片轮播.可拖动式图文表格.可拖动式选项卡.左右滑动9宫格等组件,这些组件有较多共同点.Dom构造: <div class=&qu ...

  5. C# List的使用

    1.所需引入的命名空间: using System.Collections.Generic; 2.初始化 [1]空: List<int> list = new List<int> ...

  6. 常用的图片相关方法,读取,保存,压缩,缩放,旋转,drawable转化

    import android.content.Context; import android.content.res.AssetManager; import android.content.res. ...

  7. UVA 12405 Scarecrow (基础DP)

    题意: 给出一个1*N的矩阵(就是一行的格子),其中部分格子可以有草,部分无草,现在要求放置一些稻草人在某些格子上,每个稻草人可以覆盖3个连续格子,为使得有草的格子都能被覆盖,问最少放置几个稻草人. ...

  8. 从照片网站pexels批量爬取照片

    调试中,未成功. from bs4 import BeautifulSoup import requests headers={ #'User-Agent':'Nokia6600/1.0 (3.42. ...

  9. 11gR2 如何诊断节点重启问题

    本文对如何诊断11gR2 GI环境下的节点重启问题进行了一些介绍. 首先,像10g版本一样,我们首先介绍在GI中能够导致节点重启的进程.1.Ocssd.bin:这个进程的功能和10g版本的功能基本差不 ...

  10. 设置DataGridView控件中字体的样式

    实现效果: 知识运用: DataGridView控件的公共属性DefaultCellStyle的Font属性 public Font Font  {get;set;} //获取或设置应用与DataGr ...