易截截图软件、单文件、免安装、纯绿色、仅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


相关问答:

MSSQL存储数据问题

我用的是real数据类型,但是存储小于1的数时前面的0没有了,该怎么解决,比如:我想存储0.1,在数据库里只有“.1”,0没有了,要怎么设置,或者数据类型是不是要换一种 ??
decimal(9,1)

这个貌似与类型无关
与操 ......

mssql 默认参数怎样处理? - MS-SQL Server / 基础类

我定义一个函数,有五个参数
但实际上我调用时不一定传五个参数,有时只需要传二个参数,有时只需要传三个参数等等
这种参数怎么定义呢?
SQL code:
CREATE FUNCTION [ owner_name.] function_name
( [ { ......

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:

declare @begin datetime --开始时间
declare @end datetime --结束时间
declare @startIndex int --起始值默认为8
declare @interval int --时段长
select @startIndex=8
select @ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号