Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何为每个DetailId选择CreateDate更大的FlowId_Sql Server - Fatal编程技术网

Sql server 如何为每个DetailId选择CreateDate更大的FlowId

Sql server 如何为每个DetailId选择CreateDate更大的FlowId,sql-server,Sql Server,如何为每个[DetailId]选择[FlowId]和更大的[CreateDate] 例如,详细数据 假设SQL Server 2005及更高版本,请使用如下排序函数: 试试这个 select * from t a where dt = (select max(dt) from T b where a.detailid = b.detailid) order by 1 感谢您的回复。它有最好的性能吗?或者以其他更好的方式存在?? select M.* from MyTa

如何为每个[DetailId]选择[FlowId]和更大的[CreateDate] 例如,详细数据

假设SQL Server 2005及更高版本,请使用如下排序函数:

试试这个

select * from t a
where dt = (select max(dt)
            from T b where a.detailid = b.detailid)
order by 1

感谢您的回复。它有最好的性能吗?或者以其他更好的方式存在??
select M.*
from MyTable M
inner join 
(
select DetailID,max(Date) Date
from MyTable
Group by DetailID
)T
on M.DetailID=T.DetailID
and M.Date=T.Date
order by M.DetailID
select * from t a
where dt = (select max(dt)
            from T b where a.detailid = b.detailid)
order by 1