oracle sql中count、case函数运用
答案:4 悬赏:10 手机版
解决时间 2021-01-08 20:11
- 提问者网友:你独家记忆
- 2021-01-08 15:18
oracle sql中count、case函数运用
最佳答案
- 五星知识达人网友:刀戟声无边
- 2021-01-08 15:53
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用法。
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用法。
全部回答
- 1楼网友:行路难
- 2021-01-08 18:50
为什么 不用 isnull(count(1),0)
这样就能满足你的要求,如果还有什么不明白,可以再追问
这样就能满足你的要求,如果还有什么不明白,可以再追问
- 2楼网友:躲不过心动
- 2021-01-08 17:35
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
改成这个
from hrmresource a, workflow_currentoperator b where a.id=b.userid group by a.lastname order by 2 desc
改成这个
- 3楼网友:街头电车
- 2021-01-08 15:58
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
或者用nvlselect 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
(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
或者用nvlselect 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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯