年月 a1 a2 a3 b1 b2 b3
0901 0 1 1 0 1 1
0902 1 1 1 1 1 0
0903 1 1 1 1 1 0要统计上述b1 b2 b3的状态。
条件是:
a1是0时,b1可以是0,
a1是1时,b1是1的才正确。 a2和b2,a3和b3是一组,条件与a1和b1相同如上例:
b1 b2正确,b3不正确
0901 0 1 1 0 1 1
0902 1 1 1 1 1 0
0903 1 1 1 1 1 0要统计上述b1 b2 b3的状态。
条件是:
a1是0时,b1可以是0,
a1是1时,b1是1的才正确。 a2和b2,a3和b3是一组,条件与a1和b1相同如上例:
b1 b2正确,b3不正确
解决方案 »
- 使用ORACLE建立一个函数,但是无法调用。提示:程序包或函数处于无效状态
- -----高手---帮忙!-我在DOS环境的中用ed这个命令怎么无法写入afiedt.buf????
- 急 ORACLE 测试 没有反应
- c#.net中怎么调用oracle的fuction
- 问个重命名的问题
- 连接oracle时出错是什么原因
- 数据导出的问题
- 如何取出DATE字段中的日月年,而不取出时分秒,,,,
- 如何才能到出oracle指定用户所有表的sql脚本,也就是它的表结构,而不没有里面的数据。
- 请问一个效率问题
- oracle创建序列使用参数的问题
- 问一个插入数据的问题,当插入的字段名跟oracle的关键字名一样时怎么处理??
a1是1时,b1是1的才正确。 照这个理解,只有a1是1,b1是0才不正确...那么找出a1>b1 or a2>b2 or a3>b3的就行了
case
when a1 = 1 and b1 != 1 then
'不正确'
else
'正确'
end b1,
case
when a2 = 1 and b2 != 1 then
'不正确'
else
'正确'
end b2,
case
when a3 = 1 and b3 != 1 then
'不正确'
else
'正确'
end b3,
from t
create table tb(年月 varchar(10) , a1 int,a2 int,a3 int,b1 int,b2 int,b3 int)
insert into tb values('0901', 0 , 1 , 1 , 0 , 1 , 1 )
insert into tb values('0902', 1 , 1 , 1 , 1 , 1 , 0 )
insert into tb values('0903', 1 , 1 , 1 , 1 , 1 , 0 )
goselect 年月,
case when a1 = 1 and b1 = 1 then '正确' else '不正确' end b1,
case when a2 = 1 and b2 = 1 then '正确' else '不正确' end b2,
case when a3 = 1 and b3 = 1 then '正确' else '不正确' end b3
from tbdrop table tb/*
年月 b1 b2 b3
---------- ------ ------ ------
0901 不正确 正确 正确
0902 正确 正确 不正确
0903 正确 正确 不正确(所影响的行数为 3 行)
*/[/code]
create table tb(年月 varchar(10) , a1 int,a2 int,a3 int,b1 int,b2 int,b3 int)
insert into tb values('0901', 0 , 1 , 1 , 0 , 1 , 1 )
insert into tb values('0902', 1 , 1 , 1 , 1 , 1 , 0 )
insert into tb values('0903', 1 , 1 , 1 , 1 , 1 , 0 )
go select 年月,
case when a1 = 1 and b1 = 1 then '正确' else '不正确' end b1,
case when a2 = 1 and b2 = 1 then '正确' else '不正确' end b2,
case when a3 = 1 and b3 = 1 then '正确' else '不正确' end b3
from tb drop table tb /*
年月 b1 b2 b3
---------- ------ ------ ------
0901 不正确 正确 正确
0902 正确 正确 不正确
0903 正确 正确 不正确 (所影响的行数为 3 行)
*/
SQL> SELECT TT.*,
2 DECODE(ABS(SIGN(B1 - A1)) + ABS(SIGN(B2 - A2)) + ABS(SIGN(B3 - A3)),
3 0,
4 'CORRECT',
5 'WRONG') NEW_CODE
6 FROM TABLE_NAME TT;YEARS A1 A2 A3 B1 B2 B3 NEW_CODE
----- ---------- ---------- ---------- ---------- ---------- ---------- --------
0901 0 1 1 0 1 1 CORRECT
0902 1 1 1 1 1 0 WRONG
0903 1 1 1 1 1 0 WRONG
相当于
select b1,b2,b3
...谢谢大家参与
b1 b2 b3
-- -- --
1 1 0或:
bb 結果
-- --
b1 1
b2 1
b3 0