结构是这样的
我想获取b_pid<>0的,但是结果要不等于0的b_pid要等于b_id,b_entrance要存在,要一句的哦,我现在写的在循环里又查b_entrance,感觉会慢很多

解决方案 »

  1.   

    可以结合  case  when  语法去判断     应该是可以实现的
      

  2.   

    应该不行吧
    b_pid=0的为父类,不等于0的为子类,其实就是想获取子类,但是获取到了还要得到子类所属父类的b_entrance
      

  3.   

    可以结合  case  when  语法去判断     应该是可以实现的 
      

  4.   

    select * from table where b_id<>0 and b_pid=0 and  isnull(b_entrance,'')<>''
    union 
    select * from 
    (
    select * from table where b_id<>0 and isnull(b_pid,'')<>0 and isnull(b_entrance,'')<>''
    ) A where b_pid=b_id
      

  5.   

    select * from table A left join (
    select * from table where b_pid<>0 B) on A.b_id=B.b_pid where A.b_entrance is not null
    我没这个数据库,没法测试,你试试有没有语法错误
      

  6.   


    select * from table where  b_pid=b_id and b_id<>0 and isnull(b_entrance,'')<>''
      

  7.   

    select * from table where  b_pid=b_id and b_pid<>0 and isnull(b_entrance,'')<>''
      

  8.   

    select * from T where  b_pid in(select b_id from T where b_pid=0) and b_pid<>0 and isnull(b_entrance,'')<>''
      

  9.   

    加上这句试试
    where b_pid<>0 and  b_id=b_pid and b_entrance is not null
      

  10.   

    where b_pid<>0 and b_pid=b_id and len(b_entrance )>0
      

  11.   

    亲们,有个重要的忘记说了,这是mysql的,
      

  12.   

    上面说的应该可以查出你的需求啊,MYSQL这个里面貌似没关键字,MYSQL不支持啊!
      

  13.   

    SELECT * FROM (SELECT * FROM TABLE WHERE b_pid<>0 AND b_entrance is not NULL) as t LEFT JOIN TABLE ON t.b_pid=TABLE.b_id
    你看行不行
      

  14.   

    select b_pid from yourtable where b_pid ='"b_pid"' and b_pid !="0";
      

  15.   

    select * from table where b_id in( select b_pid form table where b_pid<>0 and b_entrance is not null )
      

  16.   

    select a._b_pid as aid,b.* from 
    (select distinct a.b_pid from tt where a.b_pid<>0) a 
    left join tt b
    on a._pid=b.id and b_entrance is not null