select case (select count(*) from pcardfull where uid=9) as t when t > 0 then (select * from pcardacct) else (select * from pcardfull) end
我想判断一条sql语句的结果然后根据结果执行其他不同的sql语句

解决方案 »

  1.   

    MYSQL目录不直接的匿名语句块。
    所以如果需要用到IF,则你需要在存储过程中来处理。某些特定的需求可以通过SQL来实现,要看你的具体需求是什么了。
      

  2.   

    如果你的表pcardacct和表pcardfull的字段数相同且互相之间的数据类型兼容,则这样:select * from pcardacct where (select count(*) from pcardfull where uid=9)>0
    union all
    select * from pcardfull where (select count(*) from pcardfull where uid=9)<=0
      

  3.   

    三个表不一定有关系的,只是通过第一个sql执行结果去执行其他的语句,不想通过存储过程。
    select case (select count(*) from tb1 where uid=9) as t when t > 0 then (select * from tb2) else (select * from tb3) end
      

  4.   


    用二楼的方法吧select * from tb2 where (select count(*) from tb1 where uid=9)>0 
    union all
    select * from tb3 where (select count(*) from tb1 where uid=9)=0