简体   繁体   English

每次重新运行查询时,BQ 中的 ROW_NUMBER() 总是会发生变化

[英]ROW_NUMBER() in BQ always changes every time I rerun the query

I am using BQ and am using ROW_NUMBER to give my data an identifier.我正在使用 BQ 并使用 ROW_NUMBER 为我的数据提供标识符。 However, I found this issue where every time I rerun the query, the ROW_NUMBER would give me different outcome.但是,我发现这个问题,每次我重新运行查询时,ROW_NUMBER 都会给我不同的结果。

In my database, I have 12 fields in total and I use this query在我的数据库中,我总共有 12 个字段,我使用这个查询

ROW_NUMBER() OVER(ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) row_number

I have run this query for multiple times, but the outcome would always be different each time I run it.我已经多次运行此查询,但每次运行的结果总是不同。

For example:例如:

  • 1st Run: Merchant A has Row 1212第一次运行:商户 A 有第 1212 行
  • 2nd Run: The exact same Merchant A has Row 2938第二次运行:完全相同的商家 A 拥有第 2938 行

Is there anything wrong that I do here?我在这里做错了什么吗? Thanks谢谢

Turns out we shouldn't use number for ORDER BY in ROW_NUMBER() function.原来我们不应该在 ROW_NUMBER() function 中为 ORDER BY 使用数字。

Instead of using number, I use the field name instead and it works the magic.我没有使用数字,而是使用了字段名称,这很神奇。 The ROW_NUMBER() keeps giving me the same answer. ROW_NUMBER() 一直给我相同的答案。

Instead of this:而不是这个:

ROW_NUMBER() OVER(ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) row_number

Use this:用这个:

ROW_NUMBER() OVER(ORDER BY field_name_1, field_name_2) row_number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM