WITH suppress AS (
SELECT
sdc.nbr,
sdc.STATUS,
label,
type_nm,
opt_out,
cust_opt_out,
subject,
recordtypeid
FROM
sdc
JOIN return wr ON
sdc.id = wr.id
WHERE
recordtypeid = '0120P0'
AND STATUS LIKE '%Closed%'
)
SELECT DISTINCT
suppress.nbr,
CASE WHEN sp.nbr IS NOT NULL THEN 'Suppressed by Business Rule' ELSE 'Valid for Survey' END AS Case_Suppression,
sp.Suppression_Rule
FROM
suppress
LEFT JOIN (
SELECT nbr, 'Fulfillment' AS Suppression_rule FROM suppress WHERE type_nm = 'Fulfillment'
UNION ALL SELECT nbr, 'ARS Label' AS Suppression_rule FROM suppress WHERE cast(label AS INT) >= 1
UNION ALL SELECT nbr, 'Business Opt Out' AS Suppression_rule FROM suppress WHERE opt_out = 'true'
UNION ALL SELECT nbr, 'Customer Opt Out' AS Suppression_rule FROM suppress WHERE cust_opt_out = 'true'
UNION ALL SELECT nbr, 'Basis' AS Suppression_rule FROM suppress WHERE subject LIKE '%Basis%'
) sp ON suppress.nbr = sp.nbr
输出:
12456由业务规则履行禁止
被业务规则基础压制的5789
9765适用于Survey NULL
在Impala中返回正确的结果,但是hive没有返回正确的结果。有没有办法在hive中优化查询?