1、ifnull(num,0)如果num为空,使用0替换
比如:
select ifnull(num,0)from studentroom;
2、locate(@163.com,name)如果name子集不包含@163.com则返回0,否则返回对于子集第一次出现的位置索引
如:
select name from student where locate(@163.com,name);查出name包含@163.com的数据
3、取当前时间的前或未来几个月的每天的时间(当表数据日期不连续时,但查询需要满足日期有每天的要求)使用如下sql:
select * from (select date_add(date_format(date_sub(curdate(),interval 3moth),“%Y-%m-%d”),interval row day) date from (select 0 union all select 1 union all… select 9)s1,(select 0 union all ……select 9)s2,(select 0 union all………select 9)s3,)select @row:=-1)r)se where date_add(date_format(date_sub(curdate(),interval 3 month),“%Y-%m-%d”),interval row day)大于等于 date_sub(curdate(),interval 3 month))sk where date 小于等于 curdaye();