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
相关问答:
一个总站.三个子站共四个ASP开发的站点;数据库是MSSQL2000;四个站各有自己的数据库(四个站点的库结构都是一样的.),各有自己的信息添加后台,四个站是独立的.四个站都在同一个服务器中.
现在需要现实:
一.如何让总站 ......
例如:select a.* from (select id,code from b left join c on b.id=c.id)a where id=1
这里的where 在执行的时候, where 会优化是否进入到小括号里面执行?????
SQL code:
select id,code from b left join ......
基础表A、B如图,由于一条新闻中可能有多张图片,所以B中会出现多个图片编号对一个新闻编号的情况。
求创建C表(视图)的sql语句。
SQL code:
select
b.pictureid as 图片编号,a.newstitle as 新闻标题,a.n ......
我定义一个函数,有五个参数
但实际上我调用时不一定传五个参数,有时只需要传二个参数,有时只需要传三个参数等等
这种参数怎么定义呢?
SQL code:
CREATE FUNCTION [ owner_name.] function_name
( [ { ......
如题- -~
我有这么个东西
一个
字符串如下所示
1,2,3,4,5
然后我
需要循环的把 这些数据插入到数据库中
我该怎么做?
http://blog.csdn.net/htl258/archive/2009/09/09/4533846.aspx
SQL code:
我现 ......