Mssql如何筛选最大的

踏血无痕 发布于 2013/10/21 10:15
阅读 276
收藏 0

请问如何筛选出每个LOTID下CleanTime下最大的一笔资料?

谢谢

以下表为一个临时的表,我想再对此表做以上的筛选:

select * from (SELECT w.WORKORDER,p.NAME,p.WAFERSIZE, w.LastProcessEqp ,lh.LOTID,w.CleanTimes,lh.QTY ,w.WaferId
    FROM lothistory LH,allwafer w,product p,tool t,workorder wo
	WHERE lh.TOOLID=t.id AND lh.LOTID=w.LOTID AND wo.workorderid=w.workorder AND wo.productname=p.name
				AND LH.LOTDATETIME >= '2013-10-14 00:00:00.000' AND LH.LOTDATETIME <= '2013-10-15 00:00:00.000' AND w.CleanTimes >=3 and LH.QTY>0 and t.Name like 'fc%' and LH.ACTION='MoveOut'
				     GROUP BY w.WORKORDER,p.NAME,p.WAFERSIZE, w.LastProcessEqp,lh.LOTID,w.CleanTimes,lh.QTY ,w.waferid) a1 

加载中
0
wad12302
wad12302
分组 和 max
0
Shazi199
Shazi199
select * from tableName as a,(select LOTID,max(CleanTime) as CleanTime from tableName group by LOTID) as b where a.LOTID=b.LOTID and a.CleanTime=b.CleanTime

 

踏血无痕
能不能有更简洁点的?嘿嘿I
返回顶部
顶部