功能点1:多级查询中,当二级三级为空则查询全部
语法:select * from 表 where (字段=条件 or 条件=' ')
理解为,当条件不为空时SQL时:
select * from 表 where 字段=条件;
当条件为空时SQL时:
select * from 表 where ' '=' ';
满足了多条件并且条件是不是为空未知查询的这种情况。
功能点2:格式化日期函数
语法:DATE_FORMAT(date,format)
date 参数是合法的日期。format 规定日期/时间的输出格式
格式描述:https://www.w3school.com.cn/sql/func_date_format.asp
例子:
//studnet.time是学生表里的字段
CASE WHEN
DATE_FORMAT(studnet.time, '%Y-%m') < DATE_FORMAT('2019-11', '%Y-%m')
THEN 1 ELSE 0 END
AS stuTime