mysql 计算2个时间段之间的间距
一、计算2个时间之间的间隔
select TIMESTAMPDIFF(year, '2024-12-30' ,now())
select TIMESTAMPDIFF(month, '2024-12-30' ,now())
select TIMESTAMPDIFF(day, '2024-12-30' ,now())
二、按照年、月、周 分组统计
SELECT
YEAR(create_time) AS order_year,
WEEK(create_time, 1) AS order_week,
count(id)
FROM
sbsj_gz
GROUP BY
order_year, order_week
ORDER BY
order_year, order_week