易截截图软件、单文件、免安装、纯绿色、仅160KB

mssql 求多字段最大值2

昨天发的这个帖子:http://topic.csdn.net/u/20100407/15/1af60691-1b11-4a0a-bf85-6187add9fb4f.html

SQL code:

select tId,max(class1) maxClass
from(select tId,class1 from tb1 union all select tId,class2 from tb1) tt
group by tId
--2
select tId,max(cc1) maxClass
from(select tId,class1+class2 cc1 from tb1 union all select tId,class1+class2 cc2 from tb1) tt
group by tId



现在我要显示这个的结果
tId tName maxClass maxSum
1 test2 35 60
2 test21 85 125
3 test32 70 140

请问怎么把子查询合并起来,谢谢。


select tId,max(CASE WHEN class1>class2 THEN class1 ELSE class2 END) as maxClass,
max(class1+class2) as maxSum
from tb1
group by tId

以上假设class1 和 class2都不能为Null值


比如再加一个字段:
SQL code:

create table tb1
(
tId int,
tName nvarchar(20),
class1 int,
class2 int,
class3 int
)
insert into tb1
select 1,'test',10,20,30
union all
select 1,'test1',20,35,25
union all
select 1,'test2',30,30,40
union all
select 2,'test21',30,85,20
union all
select 2,'test22',50,75,90
union all
select 3,'test31',60,65,40
union all
select 3,'test32',70,70,50



那又怎么解决


相关问答:

总站分站MSSQL库结构

一个总站.三个子站共四个ASP开发的站点;数据库是MSSQL2000;四个站各有自己的数据库(四个站点的库结构都是一样的.),各有自己的信息添加后台,四个站是独立的.四个站都在同一个服务器中.
现在需要现实:
一.如何让总站 ......

MSSQL客户机上交数据

主机
客户机c1,c2,c3,c4,c5............
要求如何保证客户机向主机提交数据尽量实时.快速.完整
直接用insert 时,锁住主机的表.所以此方法不可行
请高手支招..
如果只插入而不读,用低隔离级别

你插你的,他插 ......

MSSQL中如何选择一行中最小的时间?

一张表,字段分为id,time1,time2,time3,time4,time5 
请问我应该如何选择ID为1的那条记录中time时间最小的值呢?
UP!

[code=SQL][/code]select min(t) from 
(select time1 as t from t1 where id ......

mssql 时间对比问题 同表同字段 数据的时间对比

求 同表同字段 数据的时间对比 语句
如:
ID DATE_TIME
1 2010年3月31日 15:14:46
2 2010年3月31日 15:20:54
3 2010年3月31日 15:23:01
4 2010年3月31日 15:25:06
5 2010年3月31日 15 ......

mssql 求多字段最大值

//相关sql
SQL code:

create table tb1
(
tId int,
tName nvarchar(20),
class1 int,
class2 int
)
insert into tb1
select 1,'test',10,20
union all
select 1,'test1',20,35
uni ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号