SQL:过去 6 个月内在不同月份进行了 4 次转移,并且 Teradata 中的标题中有特定字词 SQL?

SQL: 4 transfers in different months within the last 6 months and specific words in title in Teradata SQL?

我在 Teradata SQL 中有 table,如下所示:

我只需要 select 这些行,其中:

  1. title 中有(在任何配置中,不区分大小写)单词:"cash" 或 "pay"
  2. 在过去 6 个月内的不同月份至少进行过 4 次转会(2021-01-03 和 2021-07-03 之间)

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

ID
----
111

(简单地说,你在过去的6个月里至少收到过4次工资转移——在不同的月份)

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

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

更准确地说:

  1. Transfer -> 是当标题在任何配置中有“现金”或“支付”时,不区分大小写,
  2. ID在table中不是唯一的,因为某些ID可以接收传输例如5次,
  3. Table 的构造是你有你的工人的付款清单,你想找到他们在过去 6 个月内至少收到 4 次转账(但每次转账在不同的月份)
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 模式会话字符串比较默认不区分大小写。