我对表有一个简单的查询:
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。
COUNT
返回2
id 10。返回1
id 12。但返回NULL
id 13。在这种情况下,我想0
返回。
NVL
并且CASE
也不工作。