select debet_balance from accounting_balance_tab where ACCOUNT=100120我想用case语句实现上面的where的功能,写了下面的语句,但是数据不对,请帮忙看一下错误,谢谢select case when ACCOUNT=100120 then debet_balance end         debet_balance from accounting_balance_tab

解决方案 »

  1.   

    你这样试试
    select max(case when ACCOUNT=100120 then debet_balance end )        debet_balance from accounting_balance_tab
      

  2.   

    哦,我是说这么用没什么意义,case是限制一行的,where限制结果集的,如果你是练习的话2楼的可以
      

  3.   

    是啊
    而且,这样去做性能上不划算,这样是全表扫描的
    用WHERE可能可以用索引的
      

  4.   


    hebo2005 这个方法可以出来正确的数据,但是你出来的是其中的最大值,我要的是所有的数据
      

  5.   

    那我要是实现这样,应该如何写呢?ACCOUNT         debet_balance    
    1001             2000
    100120           3000
    1001             1000
    100120           5000我要写一个视图实现为这样
    debet_balance1001       debet_balance100120
    2000                         3000
    1000                         5000
      

  6.   

    你这样写select a.debet_balance1001,b.debet_balance100120
    from(
    select debet_balance debet_balance1001 ,rownum rnfrom accounting_balance_tab 
    where ACCOUNT =1001) a,
    (
    select debet_balance debet_balance10120 ,rownum rnfrom accounting_balance_tab 
    where ACCOUNT =100120) b
    where a.rn=b.rn