1

我有一个查询,它给了我行动的结果。现在,我想要做的是将这个结果分成两部分,对于我拥有的 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 回答