自 2012 年 10 月 1 日以来,我每天尝试选择 50 个随机文件。例如:
- 10 月 1 日 = 50 个文件
- 10 月 2 日 = 50 个文件
- 10 月 3 日 = 50 个文件
- 等等……今天
到目前为止,我每天可以选择 1 个文件,但我需要 50 个。而且我需要它们是随机的
DECLARE @DaysBack AS INT
SET @DaysBack = -25
SET NOCOUNT ON;
SELECT FileDate, MAX(FileName) FROM (
SELECT
CONVERT(VARCHAR(10),DATEADD(second,actiondate, CAST('1970-01-01 00:00:00' AS datetime)), 101) AS FileDate
,'\\directory\' + filename AS FileName
FROM Tableq q
JOIN tablec c
on q.projectid = c.projectid
AND actiondate >= Datediff(s, '19700101 00:00:00:000',
Dateadd(DAY, @DaysBack, Getutcdate()))
) x
GROUP BY FileDate
ORDER BY FileDate