想在tableau中,将下面的SQL条件转换成计算字段的写法。 请看看如何写?

业务需求是:当月同ueser、同lead_type下 且 current_state != 6 的数据 ,要加上当月同ueser、同lead_type下,在后续月份出现过,并按lead_type,user_id去重的数据

-- 1. count(lead_type=0,且 leads.score >=110分  ,且   leads. build_time 在查询月份内时,current_status!=6)
SELECT * FROM leads WHERE lead_type = 0 AND score >= 110 AND current_state != 6 AND build_time >= '2022-08-01 00:00:00' AND build_time < '2022-09-01 00:00:00'

UNION ALL

-- 2. count(第1条中,用户同lead_type,在后续月份有 大于等于1条线索,计数为1)
SELECT * FROM leads WHERE lead_type = 0 AND build_time >= '2022-09-01 00:00:00' AND current_state != 6 AND user_id IN(
    SELECT user_id FROM leads WHERE lead_type = 0 AND score >= 110 AND current_state = 6 AND build_time >= '2022-08-01 00:00:00' AND build_time < '2022-09-01 00:00:00'
)

tableau期望
tableau中链接了DB,不希望使用自定义SQL。 希望在工作表中通过一个自定义字段来实现效果。 类似下图。:

img

可以考虑数据库设计的时候增加这个字段,根据业务逻辑进行给字段赋值。或者定时任务进行更新统计