select count(*) as cnt from A where d=1 and b=1            ,cnt =1 or 0
...
select count(*) as cnt from A where d=? and b=2            ,cnt =1 or 0
...
select count(*) as cnt from A where d=? and b=3            ,cnt =1 or 0

解决方案 »

  1.   

    准确的说,b,d是unique index
      

  2.   

    建议,给出表A的简单数据,然后写出希望得到的结果,
    比如:b   c    d
          1   2    3
          3   2    0
          ....
    希望得到的结果:
    ....
      

  3.   

    b c d
    1      11 1
    2 41 1
    3 55 1
    4 8888 1
    5 9 1
    1      131 2
    2 411 2
    3 525 2
    4 8838 2
    5 93 2hope:
    select XXX where d = 1 and b between 1 and 4;
    result:
    1  11 2 41 3 55 4 8888我希望知道XXX该如何写,多谢!
      

  4.   

    select sum(decode(b,1,1,0)),sum(decode(b,1,c,0)),
           sum(decode(b,2,2,0)),sum(decode(b,2,c,0)),
           sum(decode(b,3,3,0)),sum(decode(b,3,c,0)),
           sum(decode(b,4,4,0)),sum(decode(b,4,c,0))
    from you_table where d=1 and b between 1 and 4;
      

  5.   

    decode()函数不够通用,只在ORACLE里才用