MYSQL查询当月每一天日期

MYSQL查询当月每一天日期

  • 截止到当天
SELECT
    @cdate := date_add(@cdate, INTERVAL - 1 DAY) AS days
FROM
    mysql.help_keyword,
    (
        SELECT
            @cdate := date_add(
                curdate(),
                INTERVAL 1 DAY
            )
    ) t1
WHERE
    help_keyword_id < DAY (curdate())
ORDER BY days
  • 当月每一天
SELECT
    @cdate := date_add(@cdate, INTERVAL - 1 DAY) AS days,
    @num := @num - 1 AS nowday
FROM
    mysql.help_keyword,
    (
        SELECT
            @cdate := date_add(
                last_day(curdate()),
                INTERVAL 1 DAY
            ),
            @num := (
                last_day(curdate()) - DATE_ADD(
                    curdate(),
                    INTERVAL - DAY (curdate()) + 1 DAY
                )
            ) + 2
    ) t1
WHERE
    help_keyword_id < DAY (last_day(curdate()))
ORDER BY days

注:当前sql语句引用MYSQl库自带的“help_keyword”表,用户需要有访问该表的权限!!

你可能感兴趣的:(MYSQL)