select *  from test where 语文=80 or 数学=80
union
select 姓名,0,0  from test where 语文<>80 and 数学<>80

解决方案 »

  1.   

      select 姓名 ,  语文 , (case when   数学>=80 then 数学 else 0 end) as 数学 from ta
      

  2.   

    --建立测试环境
    set nocount on
    create table test(姓名 varchar(20),语文 varchar(20),数学 varchar(20))
    insert into test select '小明','70','80'
    insert into test select '小李','95','90'
    go
    --测试
    select 姓名,
    case when 数学=80 then 语文 else 0 end,
    case when 数学=80 then 数学 else 0 end
      from test  --删除测试环境
    drop table test
     set nocount off
      

  3.   

    select 姓名,case when 数学 >80 then 语文 else 0 end  语文,
                case when 数学 >80 then 数学 else 0 end 数学
    from ta
      

  4.   

     select 姓名, (case when 数学>=80 then 语文 else 0 end) as 语文,
    (case when 数学>=80 then 数学 else 0 end) as 数学 from ta 
      

  5.   

    select 姓名,case when 数学 =80 then 语文 else 0 end  语文,
                case when 数学 =80 then 数学 else 0 end 数学
    from ta
      

  6.   

     
    /******************************************************************************/
    /*回复:20080520005总:00034                                                   */
    /*主题:条件查询                                                                          */
    /*作者:二等草                                                                            */
    /******************************************************************************/set nocount on--数据--------------------------------------------------------------------------
     
    declare @a table([姓名] varchar(4),[语文] int,[数学] int)
     insert into @a select '小明',70,80
     insert into @a select '小李',95,90--代码--------------------------------------------------------------------------
    select 姓名,
    语文=case when 数学=80 then 语文 else 0 end,
    数学=case when 数学=80 then 数学 else 0 end
      from @a 
    go/*结果--------------------------------------------------------------------------
    姓名   语文          数学          
    ---- ----------- ----------- 
    小明   70          80
    小李   0           0
    --清除------------------------------------------------------------------------*/
      

  7.   


    select 语文 = case when 数学 = 80 then 语文 else 0 end,
           数学 = case when 数学 = 80 then 80   else 0 end
    from A
      

  8.   

    --用case语句
    select 姓名,语文=case when 数学=80 then 语文 else 0 end,
            数学=case when 数学=80 then 数学 else 0 end
    from 表
      

  9.   

    不用case实现的一方法,Try:Use TestDeclare @1 Table([姓名] nvarchar(10),[语文] int,[数学] int)
    Insert Into @1
    Select '小明',   70,    80 Union All
    Select '小李',   95,    90 Select 
    [姓名],
    [语文]=(1^Abs(Sign([数学]-80)))*[语文],
    [语文]=(1^Abs(Sign([数学]-80)))*[数学]
    From @1/*
    姓名   语文   数学
    小明   70    80
    小李   95    90 
    */
      

  10.   

    倒了Use TestDeclare @1 Table([姓名] nvarchar(10),[语文] int,[数学] int)
    Insert Into @1
    Select '小明',   70,    80 Union All
    Select '小李',   95,    90 Select 
    [姓名],
    [语文]=(1^Abs(Sign([数学]-80)))*[语文],
    [数学]=(1^Abs(Sign([数学]-80)))*[数学]
    From @1/*
    姓名   语文   数学
    小明   70    80
    小李   0    0 
    */