0
点赞
收藏
分享

微信扫一扫

mysql常用查询日期语句

流沙雨帘 2024-01-19 阅读 13

-- 最近30天  

select date_add(curdate(), interval(cast(help_topic_id as signed integer) - 30) day) day

from mysql.help_topic

where help_topic_id  <= day(last_day(curdate()))

order by help_topic_id


-- 最近7天  

select date_add(curdate(), interval(cast(help_topic_id as signed integer) - 6) day) day

from mysql.help_topic

where help_topic_id  <= 6

order by help_topic_id


-- 一年内的每个月  

select mid(date_add(curdate(), interval(cast(help_topic_id as signed integer) - 11) day) ,1,7) day

from mysql.help_topic

where help_topic_id  <= 11

order by help_topic_id

举报

相关推荐

0 条评论