count 表示的是计数,也就是说记录的条数,通常和分组函数一起使用。
sql:select userId , count(*) from tablename group by userId。
case表示的是多条件判断。
sql:select ename,
case
when sal<1000 then 'lower'
when sal>1001 and sal<2000 then 'modest'
when sal>2001 and sal<4000 then 'high'
else 'too high'
end
from emp;
以上语句就是一个简单的判断工资等级的一个case用法。
select a.lastname,
(case count(1)is null then 0 else count(1) end )
from hrmresource a, workflow_currentoperator b
where a.id=b.userid
group by a.lastname order by 2 desc
或者用nvl
select a.lastname,
nvl(count(1),0) cnt
from hrmresource a, workflow_currentoperator b
where a.id=b.userid
group by a.lastname order by 2 desc
select a.lastname,ISNULL ( COUNT(1) , 0 )
from hrmresource a, workflow_currentoperator b where a.id=b.userid group by a.lastname order by 2 desc
改成这个
为什么 不用 isnull(count(1),0)
这样就能满足你的要求,如果还有什么不明白,可以再追问