0

我在Teradata SQL中有如下表:

在此处输入图像描述

我只需要选择这些行,其中:

  1. 标题中有(在任何配置中,不区分大小写)单词:“现金”或“支付”
  2. 在过去 6 个月内(​​2021-01-03 和 2021-07-03 之间)在不同月份至少有4 次转账

因此,我只需要 ID = 111,因为此 ID 在过去 6 个月内至少有 4 个标题包括“现金”或“支付”(在不同月份)

ID
----
111

(简而言之,您在过去 6 个月内至少收到了 4 次工资转移——在不同的月份)

我知道我的示例表不适合这种情况,因为它只包含少量行,但我相信描述很清楚!

我需要在Teradata SQL上执行此操作,我该怎么做?

为了更精确:

  1. 转移 -> 是当标题在任何配置中具有“现金”或“支付”时,不区分大小写,
  2. ID 在表中不是唯一的,因为某些 ID 可以接收转移例如 5 次,
  3. 构建表格,您有您的工人的付款清单,并且您想找到他们在过去 6 个月中至少收到 4 次转账(但每次转账在不同月份)
4

1 回答 1

0
select id
from tab
      -- title has (in any configuration, not case sensitive) words: "cash" or "pay"
where title like any ('%cash%', '%pay%')
      -- last 6 months
  and date between add_months(current_date, -6) and current_date
group by id
       -- at least 4 transfers in different months
having count(distinct trunc(date, 'mon')) >= 4

除非title定义了 CASESPECIFIC 或您运行 ANSI 模式会话字符串比较默认情况下不区分大小写。

于 2021-07-03T14:45:53.163 回答