要求是:现在又一个表[TableText],表中字段,Amount,Status这2个。现在的数据是
Amount    Status
5000      1
400       0当Status=1表示加法,Status=0表示减法。请问  一条Sql语句怎么得出当前Amount的值。目的是要在sql语句中判断Status后对Amount的值进行加减法。并最后得出Amount的值!
请高手帮帮忙。

解决方案 »

  1.   

    你不如
    当Status=1表示加法,Status=-1表示减法。Amount*Status即可直接实现
      

  2.   

    select Amount,
    (case when (Status= '1') then '+'--加法操作
    when (Status='0') then '-'--减法操作
    else  0 end) as '总和'
    from TableText
      

  3.   


    select case when Status=1 then 加 else 减 end as Amount from TableText
      

  4.   

    select a - b from (select sum(amount) as a  
    from peter where status=1) as t1, (select sum(amount) as b from peter where status=0) as t2
      

  5.   

     to  zhujiazhi
     感谢哈,你的答案才是我想要的。