在查询中,我尝试使用关键字时的情况。我必须在那里检查3个条件。但我得到的不是单组组功能错误。我的查询中有任何语法错误?请指导。
查询
SELECT
CASE WHEN DIST_TYPE_ID IN (5033,5034,5035,5036)
THEN MIN (b2b_start_dt +NVL(access_lead_Days,0))
ELSE
CASE WHEN MAX(overridden) = 0
THEN NVL (MIN (src_start_dt), MIN (b2b_start_dt))
ELSE MAX(B2B_START_dT) END
END as start_date
FROM prog_access_movie_v
WHERE trunc(SYSDATE) BETWEEN b2b_start_dt AND b2b_end_dt
AND (user_id IS NOT NULL OR GROUP_ID IS NOT NULL)
AND dist_type_id IN (5034) AND prog_id = (432899)
答案 0 :(得分:2)
这是select
:
SELECT (CASE WHEN DIST_TYPE_ID IN (5033, 5034, 5035, 5036)
THEN MIN(b2b_start_dt + NVL(access_lead_Days, 0))
ELSE (CASE WHEN MAX(overridden) = 0
THEN NVL(MIN(src_start_dt), MIN(b2b_start_dt))
ELSE MAX(B2B_START_dT)
END)
END) as start_date
在聚合方面,除了DIST_TYPE_ID
上的条件外,一切都很好。如果你有:
SELECT (CASE WHEN MAX(DIST_TYPE_ID) IN (5033, 5034, 5035, 5036)
THEN MIN(b2b_start_dt + NVL(access_lead_Days, 0))
ELSE (CASE WHEN MAX(overridden) = 0
THEN NVL(MIN(src_start_dt), MIN(b2b_start_dt))
ELSE MAX(B2B_START_dT)
END)
END) as start_date
或者:
SELECT (CASE WHEN SUM(CASE WHEN DIST_TYPE_ID IN (5033, 5034, 5035, 5036) THEN 1 ELSE 0 END) > 0
THEN MIN(b2b_start_dt + NVL(access_lead_Days, 0))
ELSE (CASE WHEN MAX(overridden) = 0
THEN NVL(MIN(src_start_dt), MIN(b2b_start_dt))
ELSE MAX(B2B_START_dT)
END)
END) as start_date
或者无数其他可能性,然后查询应该解析并执行。
答案 1 :(得分:0)
这是我的一个愚蠢的错误。由dist_type_id分组。
SELECT CASE WHEN DIST_TYPE_ID IN (5033,5034,5035,5036) THEN MIN (b2b_start_dt +NVL(access_lead_Days,0))
ELSE CASE WHEN MAX(overridden) = 0 THEN NVL (MIN (src_start_dt), MIN (b2b_start_dt)) ELSE MAX(B2B_START_dT) END END as start_date
FROM prog_access_movie_v
WHERE trunc(SYSDATE) BETWEEN b2b_start_dt AND b2b_end_dt
AND (user_id IS NOT NULL OR GROUP_ID IS NOT NULL)
AND dist_type_id IN (5034) AND prog_id = (432899)
group by access_lead_days, dist_type_id