mysql/mariadb学习记录——查询3

Posted 这个昵称得改

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql/mariadb学习记录——查询3相关的知识,希望对你有一定的参考价值。

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 |
+----------+
1 row in set (0.11 sec)

count()计数函数:

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

 

以上是关于mysql/mariadb学习记录——查询3的主要内容,如果未能解决你的问题,请参考以下文章

mysql/mariadb学习记录——连接查询

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

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

入门:如何从Linux命令行直接执行MySQL/MariaDB查询

数据库MySQL/mariadb知识点——查询缓存

MySQL学习记录