62,046
社区成员
发帖
与我相关
我的任务
分享
SELECT a.Tname, a.DataId,b.DataValue,
FROM Temperature a
INNER JOIN HistoryData b ON a.DataId = b.DataId
inner join
select DataId,max(日期字段) as 日期字段 from HistoryData
group by DataId)c on c.DataId = b.DataId and c.日期字段 = b.日期字段
order by b.dataid desc
SELECT a.Tname, a.DataId,b.DataValue
FROM Temperature a where not exists(
select 1 from HistoryData b where a.DataId = b.DataId And a.[日期]<b.[日期])
/***********************************************
--> 测试数据:[TB]
--> 测试时间:2009-08-10 17:04:27
--> 我的淘宝:<<戒色坊>> http://shop36766744.taobao.com/
***********************************************/
if object_id('[TB]') is not null drop table [TB]
create table [TB]([编号] varchar(2),[值] numeric(3,1),[名称] varchar(7))
insert [TB]
select 'A1',10,'采集器2' union all
select 'A1',11,'采集器2' union all
select 'A1',12,'采集器2' union all
select 'B1',90.0,'采集器1'
select * from [TB] t where not exists (select 1 from TB where t.编号=编号 and t.值<值)
/*
编号 值 名称
---- --------------------------------------- -------
A1 12.0 采集器2
B1 90.0 采集器1
(2 行受影响)
*/
drop table TB