求教一个筛选考核结果的问题。

songwin 2006-09-13 08:27:32
考核表
ID col1 col2 col3 col4
1 A B C D
2 C D C D
3 A A C A
4 D A A A
5 B B A C

col1、col2、col3、col4分别是员工的四次考核结果(每次考核结果可能是ABCD中的某一个),需要筛选四次考核中考核结果C、D次数在两次以下的人员ID。请问该如何做出来?
...全文
185 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eric_1999 2006-09-14
  • 打赏
  • 举报
回复
select id
from tab
where length(col1||col2||col3||col4) - nvl(length(replace(replace(col1||col2||col3||col4,'C',''),'D','')),0) < 2
xiaoxiao1984 2006-09-14
  • 打赏
  • 举报
回复
SQL> select id, col1,col2,col3,col4
2 from test_assess
3 where length(col1||col2||col3||col4) - nvl(length(replace(replace(col1||col2||col3||col4,'C',''),'D','')),0) < 2
4 /

ID COL1 COL2 COL3 COL4
---------- ---- ---- ---- ----
3 A A C A
4 D A A A
5 B B A C
xiaoxiao1984 2006-09-14
  • 打赏
  • 举报
回复
SQL> select id, col1,col2,col3,col4
2 from test_assess
3 where length(col1||col2||col3||col4) - nvl(length(replace(replace(col1||col2||col3||col4,'C',''),'D','')),0) >= 2
4 /

ID COL1 COL2 COL3 COL4
---------- ---- ---- ---- ----
1 A B C D
2 C D C D
lbd8848 2006-09-14
  • 打赏
  • 举报
回复
改一下:
select id from table a where exists (select count(*) from table where (col1='C' or col2='C' ... or col1='D' or col2='D') and a.id=id)<2
lbd8848 2006-09-14
  • 打赏
  • 举报
回复


select id from table where exists (select count(*) from table where col1='C' or col2='C' ... or col1='D' or col2='D')<2

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧