5.函数(超牛主讲)

教程 阿布都的都 ⋅ 于 2023-01-06 14:36:58 ⋅ 980 阅读

MySQL 函数

1. MySQL中关于函数的说明

"概念":类似java、python中的方法,将一组逻辑语句封装在方法体中,对外暴露方法名;

"好处":Ⅰ隐藏了实现细节;Ⅱ提高代码的重用性;

"调用":select 函数名(实参列表) [from 表];

"特点":Ⅰ叫什么(函数名);Ⅱ干什么(函数功能);

"分类":Ⅰ单行函数;Ⅱ分组函数;

"什么是单行函数:":作用于表中的每一行记录,一条记录出来一个结果;

"什么是聚合函数:":作用于一行或者多行,最终返回一个结果;

2. 单行函数分类

字符函数;

数学函数;

日期函数;

其他函数;

流程控制函数;

2.1 字符函数

1)length(str):获取参数值的字节个数;

对于utf8字符集来说,一个英文占1个字节;一个中文占3个字节;

对于gbk字符集来说,一个英文占1个字节;一个中文占2个字节;

mysql> select length("abcd") as length from dual;
+--------+
| length |
+--------+
|      4 |
+--------+
1 row in set (0.00 sec)

mysql> select length("abc你好") as length from dual;
+--------+
| length |
+--------+
|      9 |
+--------+
1 row in set (0.00 sec)

2) concat(str1,str2,…):拼接字符串;

mysql> select concat('first','_','name') as name;
+------------+
| name       |
+------------+
| first_name |
+------------+
1 row in set (0.00 sec)

mysql> select concat('%','name','%') as name;
+--------+
| name   |
+--------+
| %name% |
+--------+
1 row in set (0.00 sec)

3)upper(str):将字符中的所有字母变为大写;

4)lower(str) :将字符中所有字母变为小写;

mysql> select upper('Abc') as string;
+--------+
| string |
+--------+
| ABC    |
+--------+
1 row in set (0.00 sec)

mysql> select lower('Abc') as string;
+--------+
| string |
+--------+
| abc    |
+--------+
1 row in set (0.00 sec)

5)substr(str,start,len):从start位置开始截取字符串,len表示要截取的长度; 没有指定len长度:表示从start开始起,截取到字符串末尾。指定了len长度:表示从start开始起,截取len个长度。

-- 说明:MySQL中的索引是从1开始的
mysql> select substr('HelloWorldMysql',6) as output;
+------------+
| output     |
+------------+
| WorldMysql |
+------------+
1 row in set (0.00 sec)

mysql> select substr('HelloWorldMysql',6,5) as output;
+--------+
| output |
+--------+
| World  |
+--------+
1 row in set (0.00 sec)

7)trim(str):去掉字符串前后的空格; 该函数只能去掉字符串前后的空格,不能去掉字符串中间的空格。

mysql> select trim('  hello mysql      ') as output;
+-------------+
| output      |
+-------------+
| hello mysql |
+-------------+
1 row in set (0.00 sec)

-- 可以使用字节数验证
mysql> select length(trim('  hello mysql      ')) as output;
+--------+
| output |
+--------+
|     11 |
+--------+
1 row in set (0.00 sec)

8)lpad(str,len,填充字符):用指定的字符,实现对字符串左填充指定长度;

9)rpad(str,len,填充字符):用指定的字符,实现对字符串右填充指定长度;

-- 字符串长度为5,左边填充5个*,长度为10
mysql> select lpad('hello',10,'*') as output;
+------------+
| output     |
+------------+
| *****hello |
+------------+
1 row in set (0.00 sec)

-- 字符串长度为5,右边填充5个*,长度为10
mysql> select rpad('hello',10,'*') as output;
+------------+
| output     |
+------------+
| hello***** |
+------------+
1 row in set (0.00 sec)

-- 字符串长度为5,右边填充10个*,长度为15
mysql> select lpad('hello',15,'*') as output;
+-----------------+
| output          |
+-----------------+
| **********hello |
+-----------------+
1 row in set (0.00 sec)

10) replace(str,子串,另一个字符串):将字符串str中的字串,替换为另一个字符串;

mysql> select replace('hellojavaworldjava','java','bigdata') as output;
+--------------------------+
| output                   |
+--------------------------+
| hellobigdataworldbigdata |
+--------------------------+
1 row in set (0.00 sec)

-- 查询表中的手机号,并隐藏中间四位
create table phone_number (
    pnum VARCHAR(15)
);
INSERT INTO phone_number values ('13512345678'), ('13687654321'), ('15688889999');

select * from phone_number;

select REPLACE(pnum,SUBSTR(pnum,4,4),'****') as pnum from phone_number;
+-------------+
| pnum        |
+-------------+
| 135****5678 |
| 136****4321 |
| 156****9999 |
+-------------+
3 rows in set (0.00 sec)

2.2 数学函数

1)round(x,[保留的小数位数]) :四舍五入; 当对正数进行四舍五入:按照正常的计算方式,四舍五入即可。当对负数进行四舍五入:先把符号丢到一边,对去掉负号后的正数进行四舍五入,完成以后,再把这个负号,补上即可。

mysql> select round(1.5) as output;
+--------+
| output |
+--------+
|      2 |
+--------+
1 row in set (0.00 sec)

mysql> select round(-1.5) as output;
+--------+
| output |
+--------+
|     -2 |
+--------+
1 row in set (0.00 sec)

mysql> select round(-1.2) as output;
+--------+
| output |
+--------+
|     -1 |
+--------+
1 row in set (0.00 sec)

mysql> select round(1.27,1) as output;
+--------+
| output |
+--------+
|    1.3 |
+--------+
1 row in set (0.00 sec)

mysql> select round(-1.27,1) as output;
+--------+
| output |
+--------+
|   -1.3 |
+--------+
1 row in set (0.00 sec)

2)ceil(x):向上取整,返回>=该参数的最小整数。

3)floor(x):向下取整,返回<=该参数的最大整数。

mysql> select ceil(1.5) as output;
+--------+
| output |
+--------+
|      2 |
+--------+
1 row in set (0.00 sec)

mysql> select ceil(1.1) as output;
+--------+
| output |
+--------+
|      2 |
+--------+
1 row in set (0.00 sec)

mysql> select floor(1.5) as output;
+--------+
| output |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

mysql> select floor(1.8) as output;
+--------+
| output |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

4)truncate(x,D) :截断; truncate函数的理解如下:
a)D是正数,操作的是小数点右侧的小数部分。
D=1,直接从第1个位置处,砍掉后面的部分。
D=2,直接从第2个位置处,砍掉后面的部分。

​ b)D是0,直接去掉小数部分。

​ c)D是负数,操作的是小数点左侧的整数部分。
D=-1,直接从-1位置处,先砍掉后面的小数部分,
并且"从当前位置起(包括当前位置),后面整数部分替换为0"。
D=-2,直接从-2位置处,先砍掉后面的小数部分,
并且"从当前位置起(包括当前位置),后面整数部分替换为0"。

file

mysql> select truncate(1314.1314,3) as output;
+----------+
| output   |
+----------+
| 1314.131 |
+----------+
1 row in set (0.00 sec)

mysql> select truncate(1314.1314,1) as output;
+--------+
| output |
+--------+
| 1314.1 |
+--------+
1 row in set (0.00 sec)

mysql> select truncate(1314.1314,0) as output;
+--------+
| output |
+--------+
|   1314 |
+--------+
1 row in set (0.00 sec)

mysql> select truncate(1314.1314,-1) as output;
+--------+
| output |
+--------+
|   1310 |
+--------+
1 row in set (0.00 sec)

mysql> select truncate(1314.1314,-2) as output;
+--------+
| output |
+--------+
|   1300 |
+--------+
1 row in set (0.00 sec)

mysql> select truncate(-1314.1314,-1) as output;
+--------+
| output |
+--------+
|  -1310 |
+--------+
1 row in set (0.00 sec)

mysql> select truncate(-1314.1314,1) as output;
+---------+
| output  |
+---------+
| -1314.1 |
+---------+
1 row in set (0.00 sec)

mysql> select truncate(-1314.1314,-3) as output;
+--------+
| output |
+--------+
|  -1000 |
+--------+
1 row in set (0.00 sec)

5)mod(被除数,除数) :取余; 当被除数为正数,结果就是正数。当被除数为负数,结果就是负数。

mysql> select mod(10,3) as output;
+--------+
| output |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

mysql> select mod(10,-3) as output;
+--------+
| output |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

mysql> select mod(-10,3) as output;
+--------+
| output |
+--------+
|     -1 |
+--------+
1 row in set (0.00 sec)

mysql> select mod(-10,-3) as output;
+--------+
| output |
+--------+
|     -1 |
+--------+
1 row in set (0.00 sec)

2.3 日期时间函数

日期的含义:指的是我们常说的年、月、日。

时间的含义:指的是我们常说的时、分、秒。

1)now() :返回系统当前的日期和时间;

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2022-07-13 12:34:07 |
+---------------------+
1 row in set (0.00 sec)

2)curdate() :只返回系统当前的日期,不包含时间;

3)curtime() :只返回系统当前的时间,不包含日期;

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2022-07-13 |
+------------+
1 row in set (0.00 sec)

mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 12:35:10  |
+-----------+
1 row in set (0.00 sec)

4)获取日期和时间中年、月、日、时、分、秒;

获取年份:year();

获取月份:month();

获取日:day();

获取小时:hour();

获取分钟:minute();

获取秒数:second();

mysql> select year(now()) as year;
+------+
| year |
+------+
| 2022 |
+------+
1 row in set (0.00 sec)

5)STR_TO_DATE(str,format) :将日期格式的字符串,转换成指定格式的日期;

不同时间格式符表示的含义如下:

file

mysql> select str_to_date('2022年12月12日','%Y年%m月%d日') as ouput;
+------------+
| ouput      |
+------------+
| 2022-12-12 |
+------------+
1 row in set (0.00 sec)

mysql> select str_to_date('2022/12/12','%Y/%m/%d') as ouput;
+------------+
| ouput      |
+------------+
| 2022-12-12 |
+------------+
1 row in set (0.00 sec)

6)date_format():将日期转换成日期字符串; %Y-%m-%d返回的月份是01,02…这样的格式。%Y-%c-%d返回的月份是1,2…这样的格式。

mysql> select date_format('2022-6-12','%Y年%m月%d日') as output;
+-------------------+
| output            |
+-------------------+
| 2022年06月12日    |
+-------------------+
1 row in set (0.00 sec)

mysql> select date_format('2022-6-12','%Y年%c月%d日') as output;
+------------------+
| output           |
+------------------+
| 2022年6月12日    |
+------------------+
1 row in set (0.00 sec)

7)date_add(date,interval expr unit):向前、向后偏移日期和时间;

file

mysql> select curdate() as now,
    -> date_add(curdate(), interval 1 year) as 一年后,
    -> date_add(curdate(), interval 1 month) as 一月后,
    -> date_add(curdate(), interval 1 day) as 一天后;
+------------+------------+------------+------------+
| now        | 一年后     | 一月后     | 一天后     |
+------------+------------+------------+------------+
| 2022-07-13 | 2023-07-13 | 2022-08-13 | 2022-07-14 |
+------------+------------+------------+------------+
1 row in set (0.00 sec)

11)datediff(end_date,start_date) :计算两个时间相差的天数;

-- 计算2000-05-05 至今天相差的天数
mysql> select datediff(now(),'2000-05-05') as days_between;
+--------------+
| days_between |
+--------------+
|         8104 |
+--------------+
1 row in set (0.00 sec)

12)timestampdiff(unit,start_date,end_date) :计算两个时间返回的年/月/天数;

unit参数是确定(start_date,end_date)结果的单位,表示为整数,以下是有效单位:

year:年份

month:月份

day:天

hour:小时

minute 分钟

second:秒

microsecond:微秒

week:周数

quarter:季度

YEAR:年份

mysql> select timestampdiff(year,'2000-05-05 11:11:11',now()) as 间隔年份,
    -> timestampdiff(month,'2000-05-05 11:11:11',now()) as 间隔月份,
    -> timestampdiff(day,'2000-05-05 11:11:11',now()) as 间隔天数,
    -> timestampdiff(hour,'2000-05-05 11:11:11',now()) as 间隔小时,
    -> timestampdiff(minute,'2000-05-05 11:11:11',now()) as 间隔分钟,
    -> timestampdiff(second,'2000-05-05 11:11:11',now()) as 间隔秒数;
+--------------+--------------+--------------+--------------+--------------+--------------+
| 间隔年份     | 间隔月份     | 间隔天数     | 间隔小时     | 间隔分钟     | 间隔秒数     |
+--------------+--------------+--------------+--------------+--------------+--------------+
|           22 |          266 |         8104 |       194502 |     11670170 |    700210228 |
+--------------+--------------+--------------+--------------+--------------+--------------+
1 row in set (0.00 sec)

2.4 其它常用系统函数

-- 查看当前数据库版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.37    |
+-----------+
1 row in set (0.00 sec)

-- 查看当前使用的数据库
mysql> select database();
+-----------------+
| database()      |
+-----------------+
|          test03 |
+-----------------+
1 row in set (0.00 sec)

-- 查看当前用户
mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

2.5 流程控制函数

1)IF(expr1,expr2,expr3)函数:实现if-else的效果;

如果expr1表达式成立,返回结果expr2;否则返回结果expr3;

2)IFNULL(expr1,expr2)函数:判断值是否为null,是null用指定值填充;

如果expr1的值为null,则使用expr2的值填充。

-- 创建成绩表
CREATE table score (
    sid int PRIMARY key auto_increment,
    student_name VARCHAR(10),
    score decimal
);
-- 插入数据
INSERT into score values
(null, 'tom', 90),
(null, 'jerry', 75),
(null, 'lily', 88),
(null, 'lucy', 60),
(null, 'john', 99),
(null, 'jack', null);
-- 查看全部
select * from score;

-- 查询学生成绩,添加备注列
mysql> select *, if(score >= 80, '优秀', '加油') as 备注 from score;
+-----+--------------+-------+--------+
| sid | student_name | score | 备注   |
+-----+--------------+-------+--------+
|   1 | tom          |    90 | 优秀   |
|   2 | jerry        |    75 | 加油   |
|   3 | lily         |    88 | 优秀   |
|   4 | lucy         |    60 | 加油   |
|   5 | john         |    99 | 优秀   |
|   6 | jack         |  NULL | 加油   |
+-----+--------------+-------+--------+
6 rows in set (0.00 sec)

-- 查询学生成绩,如果没有成绩,显示0分
mysql> select sid, student_name, ifnull(score, 0) from score;
+-----+--------------+------------------+
| sid | student_name | ifnull(score, 0) |
+-----+--------------+------------------+
|   1 | tom          |               90 |
|   2 | jerry        |               75 |
|   3 | lily         |               88 |
|   4 | lucy         |               60 |
|   5 | john         |               99 |
|   6 | jack         |                0 |
+-----+--------------+------------------+
6 rows in set (0.00 sec)

3)case…when函数;

case … when共有三种用法:

等值判断:类似于java中switch case的效果;

区间判断:类似于python中if-elif-else的效果;

case … when和聚合函数联用;

准备数据:

SET FOREIGN_KEY_CHECKS=0;

DROP TABLE IF EXISTS `dept`;
-- 创建部门表
CREATE TABLE `dept` (
  `DEPTNO` BIGINT(20) NOT NULL AUTO_INCREMENT, -- 部门编号
  `DNAME` VARCHAR(20) DEFAULT NULL, -- 部门名称
  `LOC` VARCHAR(20) DEFAULT NULL, -- 部门地点
  PRIMARY KEY (`DEPTNO`)
) ENGINE=INNODB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8;
-- 插入数据
INSERT INTO `dept` VALUES ('10', 'ACCOUNTING', 'NEW YORK');
INSERT INTO `dept` VALUES ('20', 'RESEARCH', 'DALLAS');
INSERT INTO `dept` VALUES ('30', 'SALES', 'CHICAGO');
INSERT INTO `dept` VALUES ('40', 'OPERATIONS', 'BOSTON');

SET FOREIGN_KEY_CHECKS=0;

DROP TABLE IF EXISTS `emp`;
-- 创建员工表
CREATE TABLE `emp` (
  `EMPNO` BIGINT(20) NOT NULL AUTO_INCREMENT, -- 员工编号
  `ENAME` VARCHAR(20) DEFAULT NULL, -- 员工姓名
  `JOB` VARCHAR(20) DEFAULT NULL,-- 职位名称
  `MGR` BIGINT(20) DEFAULT NULL, -- 领导编号
  `HIREDATE` DATE DEFAULT NULL, -- 出生日期
  `SAL` DOUBLE(7,2) DEFAULT NULL, -- 工资
  `COMM` DOUBLE(7,2) DEFAULT NULL, -- 奖金
  `DEPTNO` BIGINT(2) DEFAULT NULL, -- 部门编号
  PRIMARY KEY (`EMPNO`)
) ENGINE=INNODB AUTO_INCREMENT=7935 DEFAULT CHARSET=utf8;
-- 插入数据
INSERT INTO `emp` VALUES ('7369', 'SMITH', 'CLERK', '7902', '1980-12-17', '800.00', NULL, '20');
INSERT INTO `emp` VALUES ('7499', 'ALLEN', 'SALESMAN', '7698', '1981-02-20', '1600.00', '300.00', '30');
INSERT INTO `emp` VALUES ('7521', 'WARD', 'SALESMAN', '7698', '1981-02-22', '1250.00', '500.00', '30');
INSERT INTO `emp` VALUES ('7566', 'JONES', 'MANAGER', '7839', '1981-04-02', '2975.00', NULL, '20');
INSERT INTO `emp` VALUES ('7654', 'MARTIN', 'SALESMAN', '7698', '1981-09-28', '1250.00', '1400.00', '30');
INSERT INTO `emp` VALUES ('7698', 'BLAKE', 'MANAGER', '7839', '1981-05-01', '2850.00', NULL, '30');
INSERT INTO `emp` VALUES ('7782', 'CLARK', 'MANAGER', '7839', '1981-06-09', '2450.00', NULL, '10');
INSERT INTO `emp` VALUES ('7788', 'SCOTT', 'ANALYST', '7566', '1987-04-19', '3000.00', NULL, '20');
INSERT INTO `emp` VALUES ('7839', 'KING', 'PRESIDENT', NULL, '1981-11-17', '5000.00', NULL, '10');
INSERT INTO `emp` VALUES ('7844', 'TURNER', 'SALESMAN', '7698', '1981-09-08', '1500.00', '0.00', '30');
INSERT INTO `emp` VALUES ('7876', 'ADAMS', 'CLERK', '7788', '1987-05-23', '1100.00', NULL, '20');
INSERT INTO `emp` VALUES ('7900', 'JAMES', 'CLERK', '7698', '1981-12-03', '950.00', NULL, '30');
INSERT INTO `emp` VALUES ('7902', 'FORD', 'ANALYST', '7566', '1981-12-03', '3000.00', NULL, '20');
INSERT INTO `emp` VALUES ('7934', 'MILLER', 'CLERK', '7782', '1982-01-23', '1300.00', NULL, '10');

① case … when用作等值判断的语法格式;

case 要判断的字段或表达式
when 常量1 then 要显示的值1或语句1
when 常量2 then 要显示的值2或语句2
...
else 要显示的值n或语句n
end

示例:

-- 查询员工的薪资信息,给部门编号为10的员工涨薪10%,给部门编号为20的员工涨薪20%
SELECT e.ename, e.deptno, e.sal as 原来薪资,
CASE e.deptno
    WHEN 10 THEN
        e.sal * 1.1
    WHEN 20 THEN
        e.sal * 1.2
    ELSE
        e.sal
END as 涨薪之后 
FROM emp e order by e.deptno;

② case … when用作区间判断的语法格式;

case
when 条件1 then 要显示的值1或语句1
when 条件2 then 要显示的值2或语句2
...
else 要显示的值n或语句n
end

示例:

select * from emp;
-- 查询员工的薪资信息,并分级,工资+奖金 >= 4000 的为A级,3000到4000之间的 为B级别,其他为C级别
select *, 
    CASE
    WHEN money >= 4000 THEN 'A'
    WHEN money >= 2000 AND money < 4000 THEN 'B'
    ELSE 'C'
    END as 级别 from 
(select e.ename, (e.sal + IFNULL(e.comm,0)) as money from emp e) t;

③ case…when与聚合函数的联用

准备数据:

-- 学生表
CREATE TABLE `Student`(
`s_id` VARCHAR(20),
`s_name` VARCHAR(20) NOT NULL DEFAULT '',
`s_birth` VARCHAR(20) NOT NULL DEFAULT '',
`s_sex` VARCHAR(10) NOT NULL DEFAULT '',
PRIMARY KEY(`s_id`)
);
-- 课程表
CREATE TABLE `Course`(
`c_id` VARCHAR(20),
`c_name` VARCHAR(20) NOT NULL DEFAULT '',
`t_id` VARCHAR(20) NOT NULL,
PRIMARY KEY(`c_id`)
);
-- 教师表
CREATE TABLE `Teacher`(
`t_id` VARCHAR(20),
`t_name` VARCHAR(20) NOT NULL DEFAULT '',
PRIMARY KEY(`t_id`)
);
-- 成绩表
CREATE TABLE `Score`(
`s_id` VARCHAR(20),
`c_id` VARCHAR(20),
`s_score` INT(3),
PRIMARY KEY(`s_id`,`c_id`)
);
-- 插入学生表测试数据
insert into Student values('01' , '赵雷' , '1990-01-01' , '男');
insert into Student values('02' , '钱电' , '1990-12-21' , '男');
insert into Student values('03' , '孙风' , '1990-05-20' , '男');
insert into Student values('04' , '李云' , '1990-08-06' , '男');
insert into Student values('05' , '周梅' , '1991-12-01' , '女');
insert into Student values('06' , '吴兰' , '1992-03-01' , '女');
insert into Student values('07' , '郑竹' , '1989-07-01' , '女');
insert into Student values('08' , '王菊' , '1990-01-20' , '女');
-- 课程表测试数据
insert into Course values('01' , '语文' , '02');
insert into Course values('02' , '数学' , '01');
insert into Course values('03' , '英语' , '03');

-- 教师表测试数据
insert into Teacher values('01' , '张三');
insert into Teacher values('02' , '李四');
insert into Teacher values('03' , '王五');

-- 成绩表测试数据
insert into Score values('01' , '01' , 80);
insert into Score values('01' , '02' , 90);
insert into Score values('01' , '03' , 99);
insert into Score values('02' , '01' , 70);
insert into Score values('02' , '02' , 60);
insert into Score values('02' , '03' , 80);
insert into Score values('03' , '01' , 80);
insert into Score values('03' , '02' , 80);
insert into Score values('03' , '03' , 80);
insert into Score values('04' , '01' , 50);
insert into Score values('04' , '02' , 30);
insert into Score values('04' , '03' , 20);
insert into Score values('05' , '01' , 76);
insert into Score values('05' , '02' , 87);
insert into Score values('06' , '01' , 31);
insert into Score values('06' , '03' , 34);
insert into Score values('07' , '02' , 89);
insert into Score values('07' , '03' , 98);

示例:

/*
查询各科成绩最高分、最低分和平均分,以如下形式显示:
-- 课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率
-- 及格为:>=60,中等为:70-80,优良为:80-90,优秀为:>=90
*/
mysql> select c.c_id, c.c_name, max(s.s_score) 最高分, min(s.s_score) 最低分, avg(s.s_score) 平均分,
    -> sum(case when s.s_score >= 60 then 1 else 0 end) / count(*) 及格率,
    -> sum(case when s.s_score >= 70 and s.s_score < 80 then 1 else 0 end) / count(*) 中等率,
    -> sum(case when s.s_score >= 80 and s.s_score < 90 then 1 else 0 end) / count(*) 优良率,
    -> sum(case when s.s_score >= 90 then 1 else 0 end) / count(*) 优秀率
    -> from score s left join course c
    -> on s.c_id = c.c_id
    -> group by c.c_id;
+------+--------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| c_id | c_name | 最高分    | 最低分    | 平均分    | 及格率    | 中等率    | 优良率    | 优秀率    |
+------+--------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
| 01   | 语文   |        80 |        31 |   64.5000 |    0.6667 |    0.3333 |    0.3333 |    0.0000 |
| 02   | 数学   |        90 |        30 |   72.6667 |    0.8333 |    0.0000 |    0.5000 |    0.1667 |
| 03   | 英语   |        99 |        20 |   68.5000 |    0.6667 |    0.0000 |    0.3333 |    0.3333 |
+------+--------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
3 rows in set (0.00 sec)
版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海汼部落-阿布都的都,http://hainiubl.com/topics/76021
成为第一个点赞的人吧 :bowtie:
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter