<!--近两年 -->
<select id="selectYear" resultType="Map">
SELECT DATE_FORMAT(u.reg_time,'%Y') AS dataTime
FROM users u
GROUP BY YEAR(u.reg_time)
ORDER BY dataTime ASC LIMIT 3
</select>
<!--近一年 -->
<select id="selectMon" resultType="Map">
SELECT DATE_FORMAT(u.reg_time,'%Y-%m') AS dataTime
FROM users u
WHERE u.reg_time > DATE_SUB(CURDATE(), INTERVAL 11 MONTH)
GROUP BY MONTH(u.reg_time)
ORDER BY dataTime ASC
</select>
<!-- 近30天 -->
<select id="selectDay" resultType="Map">
SELECT DATE AS dataTime FROM
(SELECT
DATE_ADD(t1.dayed,INTERVAL t2.number DAY) DATE FROM
(SELECT DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY) dayed) t1,
(SELECT @xi:=@xi+1 AS number FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) xc1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8) xc2,
(SELECT @xi:=-1) xc0 ) t2
WHERE DATE_ADD(t1.dayed ,INTERVAL t2.number DAY))TIME WHERE SUBSTRING(DATE,1,7)=SUBSTRING(CURDATE(),1,7)
</select>
sql查询时间段
最新推荐文章于 2024-07-06 03:45:26 发布