- 已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
21小时前关门了。
Improve this question
我刚刚遇到了一些问题,要在现有日期中添加随机间隔
(for每行应为随机+365天日期)
select c.name_city, t.name_author,
(select date('2020-01-01', '+365 days')) as random_date
from city c, author t
它应该看起来像
New-York - Bruce Lee - 2020-04-11
Moscow - Pushkin - 2020-07-12
date('2020 - 01 - 01','+365 days')函数向每行添加类似的+365日期
1条答案
按热度按时间uplii1fm1#
您可以使用
date('2020-01-01','+'||(365+(abs(random()) % 366))||' days')
其中
abs
确保正值,% 366
将添加到365的随机数限制在0到365之间(即随机日期将在2020-01-01的1到2年之间)。或者,如果您想要2020-01-01年内的随机日期,则
date('2020-01-01','+'||(abs(random()) % 366)||' days')