我有一個簡單的表,我已經在BigQuery中建立,我想做的是簡單地計算person_id和activity列中的特定活動的組合在該表中出現的次數,并創建一個新的列,在每一行的相鄰組合的值/計數:'combination_count'表中有成千上萬的行,所以創建一個過濾器或wheres等沒有用。
這感覺真的很簡單,但這讓我很抓狂。我已經嘗試使用計數和磁區,但它對我不起作用。
期望的結果:
| person_id | activity | combination_count||
|---|---|---|---|
| 1234 | activity_1 | 1 | |
| 1234 | activity_1 | activity_1 | 2 |
| 1234 | activity_2 | activity_2 | 1 |
| 5678 | activity_1 | 活動。 | 1 |
等等...
uj5u.com熱心網友回復:
你可以使用row_number():
select t.*。
row_number() over (partition by person_id, 活動 順序 by person_id)
from t。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/332035.html
標籤:
