select 学号,最大成绩=case when 英语>数学 and 英语>计算机 then 英语
when 数学>英语 and 数学>计算机 then 数学
when 计算机>数学 and 计算机>英语 then 计算机
end
from 学生成绩表 where 记录='0301001'
when 数学>英语 and 数学>计算机 then 数学
when 计算机>数学 and 计算机>英语 then 计算机
end
from 学生成绩表 where 记录='0301001'
解决方案 »
- 事务回滚rollback会关闭游标问题?(难度:100)
- 请教大家一个问题,如何使本地局域网所有的机器同时访问异地局域网的数据库
- 如何删除数据重复的行
- 不显示删除回复显示所有回复显示星级回复显示得分回复 Group后,查询至少包含某一项以上的数据。如何查询?[
- 在表中加入新的字段后,为什么以前该表的相关视图内容会有错误?
- 新手求教!老鸟请进来(关于SQL和ACCESS)
- 怎么给IMAGE类型的字段付值?一定给分
- VFP+SQL的表强制更新问题,试了N次了,高手请进
- 请问在vb中,怎样得到sql server的任何表中用户的使用权限?
- access中的类型在sql server的对应?
- 如何在客户端分析出服务器端一个存储过程或触发器的执行瓶颈?
- 资料表的移植
to internetcsdn(公元1979年8月10日):请问如何把多字段集到一个字段中?
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了
select 英語 as 成績 from 学生成绩表 where 學號='0301001'
union
select 数学 from 学生成绩表 where 學號='0301001'
union
select 计算机 from 学生成绩表 where 學號='0301001'
) A order by 成績 desc
英语 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
(
select 学号,数学 as 最大值 from table1
union
select 学号,英语 as 最大值 from table1
union
select 学号,计算机 as 最大值 from table1
)c
group by 学号