select 学号,最大成绩=case when 英语>数学 and 英语>计算机 then 英语
                           when 数学>英语 and 数学>计算机 then 数学
                           when 计算机>数学 and 计算机>英语 then 计算机
                           end
from 学生成绩表 where 记录='0301001'

解决方案 »

  1.   

    to ghostzxp(幽灵):我用你的方法了,但是总是提示SQL语句错误!
    to  internetcsdn(公元1979年8月10日):请问如何把多字段集到一个字段中?
      

  2.   

    reate   function f_max(@str varchar(300))
    returns float
    as
    begin
      declare  @a1 varchar(10)
      declare  @a2 varchar(10)
      declare  @a3 varchar(10)
      declare  @re  float  declare @substr varchar(30),@pos int
      select @str=@str
      select @substr='%'
      select @pos=charindex(@substr,@str)
      select @a1=substring(@str,1,@pos-1);
      select  @str=substring(@str,@pos+1,len(@str)-@pos)
      select  @pos=charindex(@substr,@str)
      select  @a2=substring(@str,1,@pos-1)
      select @a3=substring(@str,@pos+1,len(@str))  select @re=max(t.a) from  (select cast(@a1 as int) as a
      union all select cast(@a2 as int)  as a 
      union all select cast(@a3 as int) as a ) t
      return @reendselect  dbo.f_max(cast(英语 as varchar(10)+'%'+cast(数学 as varchar(10)+'%'+cast(计算机 as varchar(10))  from 表 就OK了
      

  3.   

    select top 1 * from (
    select 英語 as 成績 from 学生成绩表 where 學號='0301001'
    union
    select 数学  from 学生成绩表 where 學號='0301001'
    union
    select 计算机  from 学生成绩表 where 學號='0301001'
    ) A order by 成績 desc
      

  4.   

    create  table  table1(学号  varchar(10),
    英语 float,数学  float  ,计算机  float) 
    insert  into  table1 select  '0301001',10,20,30
    union  all  select '0301002',40,100,80
    union  all  select '0301003',80,85,90
    select 学号,dbo.f_max(Rtrim(cast(英语 as char(10)))
    +'%'+Rtrim(cast(数学 as char(10)))+'%'+Rtrim(Cast(计算机 as char(10))))  as 最大值
    from table1 
    drop table table1
    执行结果如下
    学号      最大值
    0301001   30.0
    0301002    100.0
    0301003     90.0
      

  5.   

    select 学号, max(最大值)as 最大值 from
    (
    select 学号,数学 as 最大值 from table1
    union 
    select 学号,英语 as 最大值 from table1
    union 
    select 学号,计算机 as 最大值 from table1
    )c
    group by 学号