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

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
union all
select 1,'test2',30,30
union all
select 2,'test21',30,85
union all
select 2,'test22',50,75
union all
select 3,'test31',60,65
union all
select 3,'test32',70,70



//单个字段的会,下面是求单个字段的
SQL code:

select a.* from tb1 a,(select tId,max(class1) as maxT from tb1 group by tId) b
where a.tId=b.tId and a.class1=b.maxT order by a.tId



//数据显示如下
SQL code:

tId tName class1 class2
1 test2 30 30
2 test22 50 75
3 test32 70 70



//我想显示为
SQL code:

tId tName maxClass
1 test2 35
2 test22 85
3 test32 70



我想要的结果就是class1,class2不区分,取最大值。

//谢谢。
SELECT TID,TNAME,MAX(CLASS1 )
from (
SELECT TID,TNAME,CLASS1 from TB
UNION


相关问答:

关于ACCESS和MSSQL的问题 - Web 开发 / ASP

有一个数据库里只有2W条数据不到,却有500M那么大,怎么回事啊?是ACCESS的数据库。后来我把ACCESS导入到MSSQL中,也占用了500M左右的空间,如果压缩数据库呢?请高手指点
压缩数据库?能做到么...
期待高人指点 我 ......

MSSQL如何插入不相同的记录 - .NET技术 / ASP.NET

如题,用户注册时,用户名是不能重复的,如何判断插入的记录不重复呢?
请看清楚我的题目,不要从网上抄一些答案过来,网上很多人写的先select再insert的都是瞎扯,压根就没考虑到并发性问题,我现在不想加上序列化 ......

mssql去除重复并排序的问题

SQL code:
/*
create database temp
use temp
create table employees
(
eID int identity primary key,
eName nvarchar(50) not null,
eSex smallint not null default(1),
eSort smalli ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号