我对表有一个简单的查询:
Person id Organization id employee_nam age busines_group_id
123 Zuyo 10 John 30 81
2457 Zuyo 10 Geet 69 81
56 Ghiya 12 paul 20 81
frei 13 81
SELECT
COUNT(DISTINCT ped.person_id)
FROM
per_emp_detail ped
WHERE
ped.business_group_id = 81
AND
ped.id = NVL(p_org_id, ped.organization_id);
SELECT
NVL(COUNT(DISTINCT ped.person_id), 0)
FROM
per_emp_detail ped
WHERE
ped.business_group_id = 81
AND
ped.id = NVL(p_org_id, ped.organization_id);
p_org_id
是我传递的参数,可以是10,12或13。
对于ID为12,COUNT
会为ID为2
返回1
,但对于ID为13,则返回NULL
。
我希望在这种情况下返回0
。
NVL
和CASE
也无效。
答案 0 :(得分:1)
尝试MAX:
nvl(max(count(DISTINCT ped.person_id)),0)