数据库: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

解决方案 »

  1.   

    不知道是不是我没有理解正确,反正我觉得那个表table(a,b,c)就是你要的答案。
      

  2.   

    另外,你的select语句完全可以这样写:
    select c from table where (a=A1 or a=A2) or (b=B1 or b=B2)
      

  3.   

    select a,b,c from table where (a=A1 or a=A2) or (b=B1 or b=B2)
      

  4.   

    select distinct c from table
      

  5.   

    faint……转回头来看居然发现自己写错了。select a,b,c from table where (a=A1 or a=A2) And (b=B1 or b=B2)
                                                 ^^^刚才不小心写成or了。失败。
      

  6.   

    select "" as c1,"" as c2,c as c3,"" as c4 
           from table where (a=A1 or a=A2) or (b=B1 or b=B2)
    这样应该可以
      

  7.   

    select a,b,c from table where (a=A1 or a=A2) And (b=B1 or b=B2)
      

  8.   

    我想要的结果是c1就是当a=A1,b=B1时的值;c2是当a=A1,b=B2时的值
                  c3就是当a=A2,b=B1时的值;c4是当a=A2,b=B2时的值