SELECT DATE_ADD('2024-02-01',INTERVAL(CAST(HELP_TOPIC_ID AS SIGNED INTEGER))DAY) temp_date
FROM MYSQL.HELP_TOPIC
WHERE HELP_TOPIC_ID <(to_days('2024-02-29')- to_days('2024-02-01'))+1ORDERBY HELP_TOPIC_ID
写法2:请求太慢了
SELECT*FROM(SELECT adddate('2020-01-01',t4.i *10000+ t3.i *1000+ t2.i *100+ t1.i *10+ t0.i) temp_date
FROM(SELECT0 i UNIONSELECT1UNIONSELECT2UNIONSELECT3UNIONSELECT4UNIONSELECT5UNIONSELECT6UNIONSELECT7UNIONSELECT8UNIONSELECT9) t0,(SELECT0 i UNIONSELECT1UNIONSELECT2UNIONSELECT3UNIONSELECT4UNIONSELECT5UNIONSELECT6UNIONSELECT7UNIONSELECT8UNIONSELECT9) t1,(SELECT0 i UNIONSELECT1UNIONSELECT2UNIONSELECT3UNIONSELECT4UNIONSELECT5UNIONSELECT6UNIONSELECT7UNIONSELECT8UNIONSELECT9) t2,(SELECT0 i UNIONSELECT1UNIONSELECT2UNIONSELECT3UNIONSELECT4UNIONSELECT5UNIONSELECT6UNIONSELECT7UNIONSELECT8UNIONSELECT9) t3,(SELECT0 i UNIONSELECT1UNIONSELECT2UNIONSELECT3UNIONSELECT4UNIONSELECT5UNIONSELECT6UNIONSELECT7UNIONSELECT8UNIONSELECT9) t4
) date_list
WHERE temp_date BETWEEN'2024-02-01'AND'2024-02-29'
写法3:外面传参数进来当临时表(推荐)
<selectid="listCompare"resultType="com.ruoyi.business.vo.TDeviceLogVo">
SELECT A.temp_date
FROM (
<foreachcollection="dateList"index="index"item="item"open="("separator="union"close=")">
select #{item} as temp_date
</foreach>
) A
</select>