数据库:ACCESS或SQLSERVER
要求:
表table(a,b,c)
其中a有两个值A1,A2,b也有两个值B1,B2
求在四种组合A1B1,A1B2,A2B1,A2B2下c的值,已知四种组合中的值唯一
除了下面的方法外,还有其他的方法吗?
sql=select c as c1,"" as c2, "" as c3,"" as c4
from table where a=A1 and b=B1
union
select "" as c1,c as c2, "" as c3,"" as c4
from table where a=A1 and b=B2
union
select "" as c1,"" as c2,c as c3,"" as c4
from table where a=A2 and b=B1
union
select "" as c1,"" as c2, "" as c3,c as c4
from table where a=A2 and b=B2
要求:
表table(a,b,c)
其中a有两个值A1,A2,b也有两个值B1,B2
求在四种组合A1B1,A1B2,A2B1,A2B2下c的值,已知四种组合中的值唯一
除了下面的方法外,还有其他的方法吗?
sql=select c as c1,"" as c2, "" as c3,"" as c4
from table where a=A1 and b=B1
union
select "" as c1,c as c2, "" as c3,"" as c4
from table where a=A1 and b=B2
union
select "" as c1,"" as c2,c as c3,"" as c4
from table where a=A2 and b=B1
union
select "" as c1,"" as c2, "" as c3,c as c4
from table where a=A2 and b=B2
select c from table where (a=A1 or a=A2) or (b=B1 or b=B2)
^^^刚才不小心写成or了。失败。
from table where (a=A1 or a=A2) or (b=B1 or b=B2)
这样应该可以
c3就是当a=A2,b=B1时的值;c4是当a=A2,b=B2时的值