私は、ユーザが「入力」ページおよび/または「結果」ページ内でデータを入力できる2つのツールのユーザ入力用のユーザ追跡データを持っています。難しいケースステートメントの策定
平均年齢はページ単位でuser_idで行いたいとします。 avg(age) over (partition by user_id, page_name)
ですが、現状ではInputs
とResults
の間に重複があることが多いので、平均化する前にクリーンアップしてください。現在のフォームの
(簡体字)スニペットは:
ここpage_name page_type user_id age
Tool 2 Inputs 2174246 53
Tool 2 Inputs 2174246 50
Tool 2 Results 2174246 53
Tool 1 Inputs 2425226 65
Tool 1 Results 2425226 65
Tool 1 Results 2425226 50
Tool 2 Inputs 2427115 50
Tool 2 Results 2427115 55
Tool 1 Results 620071 65
Tool 2 Inputs 2427536 55
私は(ユーザIDおよびツールで)考えていますが、それを記述する方法がわからないものです:
case when Results age = Inputs age then return Results age
when Results age is not null and Inputs age is null then return Results age
when Inputs age is not null and Results age is null then return Inputs age
when Results age is not null and Inputs age is not null then return each
ケースステートメントは、私が何かを見逃していない限り、すべてのシナリオを処理する必要があります:
select user_id, page_name, avg(case statement for age) over (partition by user_id, page_name) as age
page_name user_id age
Tool 2 2174246 51.5
Tool 1 2425226 67.5
Tool 2 2427115 52.5
Tool 1 620071 65
Tool 2 2427536 55
データはハイブ、 SQLはここでもうまくいくはずです。
ありがとうございました!
あなたのcase文は、全体構成は無用になりパーティショニング、前に実行されます。結果と入力のためのステートメントを分離してみてください。 – Alex