1
I have the following query:

Select 
Count(Distinct Case When Play.Uuid Like ('i~%') Then Tap.Player_Id End) As Tapjoy_Ios
From
Player_Tapjoy Tap
Inner Join 
Player Play 
On 
Tap.Player_Id = Play.Player_Id
Where 
Trunc(Tap.Create_Dtime) >= To_Date('2012-Jan-01','yyyy-mon-dd')

我想添加另一个类似的约束,以便结果出现在 play.uuid like ('i~%' or 'ti~%')..但这似乎不起作用。我怎么能实现这个?

4

3 回答 3

1

虽然答案是正确的,但您在错误的级别上应用了条件。您通常希望过滤数据以获得更好的性能,尽管此处的 LIKE 子句使其不那么重要。

    Select Count(Distinct Tap.Player_Id) As Tapjoy_Ios
      From Player_Tapjoy Tap
Inner Join Player Play On Tap.Player_Id = Play.Player_Id
     Where Tap.Create_Dtime >= To_Date('2012-Jan-01','yyyy-mon-dd')
       And (Play.Uuid Like ('i~%') OR Play.Uuid Like ('ti~%'))

正如问题中所写,它正在处理所有行并在那些与 LIKE 模式不匹配的行上发出嘶嘶声。您也不想对不允许使用索引的列运行函数 - 我已经更新了您的日期过滤器。你真的不需要TRUNC。

于 2012-09-26T02:30:47.750 回答
1

您需要两个LIKE由逻辑连接的完整子句OR,每个子句都有LIKE关键字的左侧和右侧(左侧的列,右侧的字符串值)。

count(Distinct Case When (Play.Uuid Like 'i~%') OR (Play.Uuid LIKE 'ti~%') Then Tap.Player_Id End) As Tapjoy_Ios

REGEXP_LIKE您也可以使用正则表达式 g对单个 进行此操作^t?i~.+

count(Distinct Case When REGEXP_LIKE(Play.Uuid, '^t?i~.+') Then Tap.Player_Id End) As Tapjoy_Ios
  • ^是字符串的开头
  • t?是可选的t
  • i~是字面的
  • .+是任何剩余的字符,相当于%一个常规的LIKE.
于 2012-09-26T02:12:40.917 回答
1

你可以只使用一个OR

Select Count(Distinct Case When Play.Uuid Like ('i~%')
                          OR Play.Uuid Like ('ti~%') 
                      Then Tap.Player_Id End) As Tapjoy_Ios
From Player_Tapjoy Tap
Inner Join Player Play 
  On Tap.Player_Id = Play.Player_Id
Where Trunc(Tap.Create_Dtime) >= To_Date('2012-Jan-01','yyyy-mon-dd')
于 2012-09-26T02:13:46.010 回答