比如有一个表 tid  name  score date 
1   a      20   2011
2   b      30   2012
3   c      40   2013  然后 select id,name,score from t where id=1 and date<2011 这样的话就没有返回结果 我想要的结果是 
id name score 
1   a   0

解决方案 »

  1.   

    select id,name,case when date<2011 then 0 else score end score from t where id=1
      

  2.   


    万一我有一条数据 是
    id name score date
    1   a   10    2010那你这样 不就 掉了一条数据 
      

  3.   


    万一我有一条数据 是
    id name score date
    1   a   10    2010那你这样 不就 掉了一条数据 怎么会呢,还是会查出2条啊
      

  4.   


    万一我有一条数据 是
    id name score date
    1   a   10    2010那你这样 不就 掉了一条数据 怎么会呢,还是会查出2条啊
    我只想要一条数据  如果2011前没数据 就显示 
    id name score
    1   a    0如果2011前有数据 就显示 
    id  name  score
    1    a     10
      

  5.   

    用个sum求和一下就可以了,楼主可以发散一下..
      

  6.   

    select id,NAME, DECODE(SIGN(2011-date),1,score,0) from t where id=1
      

  7.   

    select  id,name, case  when  (select score from t where id=1 and date<2011) is null then  0  else score end  from t where t.id=1