mysql/mariadb学习记录——查询3(AVG、SUM、COUN…

2018-06-18 01:24:52来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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 |
+------+-------------+

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:BCNF范式及其分解方法(对一次Lab作业的总结)

下一篇:MySQL-ALTER TABLE命令学习[20180503]