select case  when b2 >(select sum(a3) from ta) then '1' else '0' end 
from tb

解决方案 »

  1.   

    --> 1 , <= 0
    select case when sum(A3) > (select b2 from B) when 1 else 0 end from A----------------------------------------------------------------------
    select case when B2 > (select sum(A3) from A) when 1 
                when B2 < (select sum(A3) from A) when 0
           end
    from B 
      

  2.   

    /*
    -- Author:Flystone 
    -- Version:V1.001  Date:2008-05-15   初稿
    -- Version:V1.002  Date:2008-05-16  1、 处理空格带来的异常
    --                                  2、 增加了形如yyyy-mm-dd hh:mm:ss
    --                                               yyyy-m-d h:m:s     格式的处理
    */-- Test Data: ta
    If object_id('ta') is not null 
        Drop table ta
    Go
    Create table ta(A1 int,A2 int,A3 int,A4 varchar(2))
    Go
    Insert into ta
    select 1,1,1,'aa' union all
    select 4,5,2,'bb' 
    Go
    -- Test Data: tb
    If object_id('tb') is not null 
        Drop table tb
    Go
    Create table tb(B1 varchar(2),B2 int,B3 varchar(2),B4 int)
    Go
    Insert into tb
     select 'as',21,'qw',10 union all
     select 'ab',23,'qs',5 
    Go
    --Start
    select b1,b3,b4,case  when b2 >(select sum(a3) from ta) then '1' else '0' end  
    from tb 
    --Result:
    /*
    b1   b3   b4               
    ---- ---- ----------- ---- 
    as   qw   10          1
    ab   qs   5           1(所影响的行数为 2 行)
    */
    --End