pandas sqlite 3添加日期间隔[已关闭]

tquggr8v  于 2023-02-11  发布在  SQLite
关注(0)|答案(1)|浏览(125)

编辑问题以包含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日期

uplii1fm

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')

相关问题