AVG() 求平均数函数:

//求emp表中的sal属性的平均值
mysql> select avg(sal) as salAverage from emp;
+-------------+
| salAverage |
+-------------+
| 2073.214286 |
+-------------+
1 row in set (0.11 sec) //emp表数据
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+

  

SUM()求和函数:

mysql> select sum(sal) as salSum from emp;
+----------+
| salSum |
+----------+
| 29025.00 |
+----------+
row in set (0.11 sec)

count()计数函数:

//查看student表中的男女生人数
mysql> select ssex,count(sage) from student group by ssex;
+------+-------------+
| ssex | count(sage) |
+------+-------------+
| M | |
| 女 | |
| 男 | |
+------+-------------+

mysql/mariadb学习记录——查询3(AVG、SUM、COUNT)函数的更多相关文章

  1. mysql/mariadb学习记录——查询2

    Alias——使用一个列名别名AS 关键字: mysql> select sno as studentId,sname as studentName from student; +------- ...

  2. mysql/mariadb学习记录——查询

    连接查询:同时设计两个及以上的表的查询 连接条件或连接谓词:用来连接两个表的条件一般格式: [<表名1>]<列名1> <比较运算符> [<表名2>]&l ...

  3. mysql/mariadb学习记录——连接查询(JOIN)

    //本文使用的数据表格//persons表中id_p为主键//orders表中id_o为主键,id_p为外键参考persons表中的id_p mysql> select * from perso ...

  4. mysql/mariadb学习记录——创建删除数据库、表的基本命令

    查看已有的数据库: mysql> show databases; +--------------------+ | Database | +--------------------+ | inf ...

  5. mysql/mariadb学习记录——limit

    在mysql/mariadb 中可以用limit来限制查询的条数.例子如下: 1.limit后加一个参数 limit n: //选中查询所有结果中的前两条记录并返回 mysql> ; +---- ...

  6. MySQL/MariaDB数据库的查询缓存优化

    MySQL/MariaDB数据库的查询缓存优化 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL架构 Connectors(MySQL对外提供的交互接口,API): ...

  7. mysql踩坑记录之limit和sum函数混合使用问题

    问题复盘本次复盘会用一个很简单的订单表作为示例. 数据准备订单表建表语句如下(这里偷懒了,使用了自增ID,实际开发中不建议使用自增ID作为订单ID) CREATE TABLE `order` ( `i ...

  8. MySQL/MariaDB学习笔记——mysql.user表中存在多个root用户问题理解

    mysql.user表中存在多个root用户问题 问题描述:使用 SELECT host,user FROM mysql.user 发现mysql.user表中存在三个root用户,如下 持着对中几个 ...

  9. MariaDB学习记录

    MariaDB的学习 MariaDB的学习 关于MariaDB的历史,不再概述 下面是mariadb的官网:https://mariadb.com/ 同样的,MariaDB一样有连接java的jar包 ...

随机推荐

  1. 在Eclipse中指定JDK

    1.Windows下的Eclipse中的eclipse.ini -startup plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540 ...

  2. new 关键字

    学习过的调用或者是执行函数的方式有几种? ①函数名+小括号 ②事件处理函数 ③定时器 ④数组里面的元素是函数,枚举出来执行 ⑤new关键字 提示:需要注意new 关键字需要在函数名前面使用 构造函数是 ...

  3. 使用DataTables插件与后台对接表格

    function getResults(){ var callResults = $.ajax({ url: "....", //接口url type: "GET&quo ...

  4. LeetCode题解之Number of 1 Bits

    1.题目描述 2.问题分析 使用C++ 标准库的 bitset 类,将整数转换为 二进制,然后将二进制表示转换为字符串,统计字符串中 1 的个数即可. 3.代码 int hammingWeight(u ...

  5. 18c新特性的一些小结(from JimmyHe)

    Oracle 18c在2018-02-16 release出来的,还是秉承着Oracle的cloud first理念,18c现在cloud和Engineered Systems上推出,想在传统的机器上 ...

  6. [翻译] VBFPopFlatButton

    VBFPopFlatButton https://github.com/victorBaro/VBFPopFlatButton Flat button with 21 different states ...

  7. [翻译] USING GIT IN XCODE [2] 在XCODE中使用GIT[2]

    USING GIT IN XCODE http://www.cimgf.com/2013/12/10/using-git-in-xcode/ USING AN EXISTING REMOTE PROJ ...

  8. [翻译] M13BadgeView

    M13BadgeView M13BadgeView is a customizable badge view for iOS applications. The badge is built to b ...

  9. UINavigationController便于pop的category

    UINavigationController便于pop的category 效果图: 这个category是为了方便UINavigationController用于跳转到指定的控制器当中,用于跳级,如果 ...

  10. 导出AD用户所属组,查询AD用户(aduser)

    $ous="admin","bladmin","af","dd"for($i=0;$i -lt 2;$i++) { $o ...