查询以获取Google BigQuery中每个ID的两个示例记录

时间:2016-08-12 17:23:01

标签: google-bigquery

我正在尝试为表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

1 个答案:

答案 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