sql计算列问题
现有一张表有A B C D四个字段都是int类型
D列为计算列
如果A=0并且B=1并且C=1
计算列D=1否则D=0
现在问的是这个计算列怎么写请各位高手指点一下
[解决办法]
create table tb(a int ,b int,c int ,d as case when A=0 and B=1 and C=1 then 1 else 0 end)
go
drop table tb
[解决办法]
create table tb(a int ,b int,c int ,d as case when A=0 and B=1 and C=1 then 1 else 0 end)goinsert into tb (a,b,c) values(0,1,1)insert into tb (a,b,c) values(0,2,1)insert into tb (a,b,c) values(0,1,2)insert into tb (a,b,c) values(1,1,1)insert into tb (a,b,c) values(2,1,1)select * from tbdrop table tb/*a b c d ----------- ----------- ----------- ----------- 0 1 1 10 2 1 00 1 2 01 1 1 02 1 1 0(所影响的行数为 5 行)*/
[解决办法]
[解决办法]
select A,B,case C when A=1 and B=1 then D else C when A=2 and B=2 then E else C end as C,D,E from table --前提是D,E都要有数据。。。。