select * from table where (case when instr(cols,'A')>0 then 1 end)+ (case when instr(cols,'B')>0 then 1 end)+ (case when instr(cols,'C')>0 then 1 end)+ (case when instr(cols,'D')>0 then 1 end) >=2;
/* Formatted on 2011/06/13 14:08 (Formatter Plus v4.8.8) */ SELECT SYSDATE FROM DUAL WHERE (CASE WHEN INSTR ('abcd', 'a') > 0 THEN 1 END) + (CASE WHEN INSTR ('abcd', 'b') > 0 THEN 1 END) + (CASE WHEN INSTR ('abcd', 'c') > 0 THEN 1 END) + (CASE WHEN INSTR ('abcd', 'd') > 0 THEN 1 END) >= 2
数据库是oracle的 比如说: name A B C D 测试 0 411 423 0 0为空值
WHEN INSTR ('abcd', 'a') > 0 这里的'abcd','a' abcd是四个字段,数据库中怎么把四个字段放进去?
select * from t where case when a is null then '0' else '1' end+ case when b is null then '0' else '1' end+ case when c is null then '0' else '1' end+ case when d is null then '0' else '1' end =2;
好吧 重新描述一遍吧 oracle数据库 查询table中的一条记录至少有填写四个字段A、B、C、D中的其中两个字段 查询结果为以下 name A B C D 测试 0 411 423 0 测试1 657 411 423 0 测试2 941 411 423 2810为空值,由于比较的急,所以犯了点错误
select * from ABCD t where (decode(t.a, 0, 0, 1) + decode(t.b, 0, 0, 1) + decode(t.c, 0, 0, 1) + decode(t.d, 0, 0, 1)) >= 2;
select * from table where (case when instr(A||B||C||D,'A')>0 then 1 end)+ (case when instr(A||B||C||D,'B')>0 then 1 end)+ (case when instr(A||B||C||D,'C')>0 then 1 end)+ (case when instr(A||B||C||D,'D')>0 then 1 end) >=2;
(case when instr(cols,'B')>0 then 1 end)+
(case when instr(cols,'C')>0 then 1 end)+
(case when instr(cols,'D')>0 then 1 end) >=2;
SELECT SYSDATE
FROM DUAL
WHERE (CASE
WHEN INSTR ('abcd', 'a') > 0
THEN 1
END)
+ (CASE
WHEN INSTR ('abcd', 'b') > 0
THEN 1
END)
+ (CASE
WHEN INSTR ('abcd', 'c') > 0
THEN 1
END)
+ (CASE
WHEN INSTR ('abcd', 'd') > 0
THEN 1
END) >= 2
比如说:
name A B C D
测试 0 411 423 0
0为空值
case when a is null then '0' else '1' end+
case when b is null then '0' else '1' end+
case when c is null then '0' else '1' end+
case when d is null then '0' else '1' end =2;
oracle数据库
查询table中的一条记录至少有填写四个字段A、B、C、D中的其中两个字段
查询结果为以下
name A B C D
测试 0 411 423 0
测试1 657 411 423 0
测试2 941 411 423 2810为空值,由于比较的急,所以犯了点错误
A表:
colA colB colC
1 2 3
2 2 2
3 3 3
想得到的结果:
colA colB colC
2 2 2
from ABCD t
where (decode(t.a, 0, 0, 1) + decode(t.b, 0, 0, 1) + decode(t.c, 0, 0, 1) +
decode(t.d, 0, 0, 1)) >= 2;
(case when instr(A||B||C||D,'B')>0 then 1 end)+
(case when instr(A||B||C||D,'C')>0 then 1 end)+
(case when instr(A||B||C||D,'D')>0 then 1 end) >=2;