首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

:sql查询各字段最高值

2012-03-09 
高手请进:sql查询各字段最高值表tb:idnamemnyraterefund1大大15.1232了了12.0143小小9.031想得各字段最大

高手请进:sql查询各字段最高值
表tb:
id name mny rate refund
1 大大 15.1 2 3
2 了了 12.0 1 4
3 小小 9.0 3 1

想得各字段最大值得到如下结果:
id name mny rate retfun
1 大大 是 否 否
2 了了 否 否 是
3 小小 否 是 否

有没有办法,或有什么好思路



[解决办法]
case when
[解决办法]

SQL code
declare @T table (id int,name varchar(4),mny numeric(3,1),rate int,refund int)insert into @Tselect 1,'大大',15.1,2,3 union allselect 2,'了了',12.0,1,4 union allselect 3,'小小',9.0,3,1select id,name,case when mny=(select max(mny) from @T) then '是' else '否' end as mny,case when rate=(select max(rate) from @T) then '是' else '否' end as rate,case when refund=(select max(refund) from @T) then '是' else '否' end as refundfrom @T/*id          name mny  rate refund----------- ---- ---- ---- ------1           大大   是    否    否2           了了   否    否    是3           小小   否    是    否*/
[解决办法]
http://blog.csdn.net/wufeng4552/article/details/4681510

热点排行