0

我有以下查询:

--Total DLs--
select sum(DLs) as DLs_Total
From
 (
Select
Count(T.Create_Dtime) As Dls
From Player_Tapjoy T 
Inner Join Player P On T.Player_Id=P.Player_Id
Where P.ReferredBy IS NULL
Union All
Select
Count(Pt.Create_Dtime) As DLs
From Player_Aux_Pt Pt
Inner Join Player P On Pt.Player_Id=P.Player_Id
Where
Pt.Site = 'AppCircle'
And P.ReferredBy IS NULL
)

我将运行此报告两次,一次用于“And P.ReferredBy is Null”,一次用于“And P.ReferredBy is NOT Null”。

我觉得这可能是切换到案例查询的好时机......所以如果在 null 或非 null 的情况下,一个查询会产生两个单独的结果?

4

1 回答 1

1

是的,您可以在此处使用案例。我没有测试以下查询,但请检查它是否有效:

--Total DLs--
select sum(DLs_ReferredBy_Null) as DLs_ReferredBy_Null_Total, sum(DLs_ReferredBy_NotNull) as DLs_DLs_ReferredBy_NotNull_Total
From
 (
Select
Count(CASE WHEN P.ReferredBy IS NULL THEN T.Create_Dtime END) As DLs_ReferredBy_Null,
Count(CASE WHEN P.ReferredBy IS NOT NULL THEN T.Create_Dtime END) As DLs_ReferredBy_NotNull
From Player_Tapjoy T 
Inner Join Player P On T.Player_Id=P.Player_Id
Union All
Select
Count(CASE WHEN P.ReferredBy IS NULL THEN Pt.Create_Dtime END) As DLs_ReferredBy_Null,
Count(CASE WHEN P.ReferredBy IS NOT NULL THEN Pt.Create_Dtime END) As DLs_ReferredBy_NotNull
From Player_Aux_Pt Pt
Inner Join Player P On Pt.Player_Id=P.Player_Id
Where
Pt.Site = 'AppCircle'
)
于 2012-09-22T01:36:10.273 回答