1

アクションの結果を表示するクエリがあります。さて、私がやりたいのは、この結果を2つの部分に分割することです。これは、私が持っている2つの別々のユーザーグループに対して...

Select Sum(Actions) From
(
Select
Count(Create_Dtime) As Actions
From Player_Tapjoy
Where
Trunc(Create_Dtime) = To_Date('2012-sep-12','yyyy-mon-dd')
Union All
Select 
Count(Create_Dtime) As Actions
From Player_aux_pt
Where Site = 'AppCircle' And
Trunc(Create_Dtime) = To_Date('2012-sep-12','yyyy-mon-dd')
);

現在のクエリの両方のテーブルにplayer_idタグがあります。player_sourceという別のテーブルがあり、各player_idのグループID(1〜100)があります。現在のクエリをplayer_idによってplayer_sourceテーブルにマップして、特定のgroup_id(たとえば、1、2、3、4、および6)のみを含めることができるようにします。助言がありますか?

最初のクエリに含めたいIDは、次のクエリから取得されます。

Select Player_Id From Player_Source S Inner Join Feature_Group_Xref F 
On S.Group_Id=F.Group_Id
where f.feature_name = 'BC'
4

1 に答える 1

1

特定のグループ ID のみを含める必要があり、player_source テーブルにグループ ID があるため、player_source テーブルを「メイン」テーブル (tapjoy および aux_pt) に結合する必要があります。結果を集計していて、集計後に個々のレコードをフィルタリングできないため、UNION の各コンポーネントでそれを行う必要があります。group_ids を取得するためのクエリを提供したので、tapjoy/aux_pt から feature_group_xref に取得するために必要だったのは内部結合だけです。

結果は次のとおりです。

Select Sum(Actions) From
(
Select
Count(t.Create_Dtime) As Actions
From Player_Tapjoy t inner join player_source s on (t.player_id = s.player_id)
Inner Join Feature_Group_Xref F On (S.Group_Id=F.Group_Id and f.feature_name = 'BC')
Where Trunc(t.Create_Dtime) = To_Date('2012-sep-12','yyyy-mon-dd')
Union All
Select 
Count(a.Create_Dtime) As Actions
From Player_aux_pt a inner join player_source s on (a.player_id = s.player_id)
Inner Join Feature_Group_Xref F On (S.Group_Id=F.Group_Id and f.feature_name = 'BC')
Where a.Site = 'AppCircle' And
Trunc(a.Create_Dtime) = To_Date('2012-sep-12','yyyy-mon-dd')
)
于 2012-09-13T19:08:52.107 に答える