我正在尝试为表tb1中的每个id获取两个样本记录。我尝试使用以下查询但未获得所需的结果。
任何帮助都将不胜感激。
SELECT
Id,
DateTime
FROM (
SELECT
Id,DateTime,RAND() AS rnd,
ROW_NUMBER() OVER(PARTITION BY DateTime ORDER BY rnd) AS pos
FROM
[proj:tb1.UtilDateTime] )
WHERE pos <= 2
ORDER BY VehicleId,DateTime
答案 0 :(得分:0)
尝试
SELECT
Id,
DateTime
FROM (
SELECT
Id,DateTime,RAND() AS rnd,
ROW_NUMBER() OVER(PARTITION BY Id ORDER BY rnd) AS pos
FROM
[proj:tb1.UtilDateTime] )
WHERE pos <= 2
ORDER BY Id,DateTime