去掉重复值,找出最新更改的数据(在先等)
sh ph cd rq
65X0512 70055 66.80 20070315
65X0512 70055 66.30 20070320
65X0512 70056 66.40 20070315
65X0512 70056 65.90 20070320
65X0512 70057 63.60 20070315
65X0512 70057 63.10 20070320
想查出sh,ph相同的情况的最后更新的数据,谢谢:)))
65X0512 70055 66.30 20070320
65X0512 70056 65.90 20070320
65X0512 70057 63.10 20070320
------解决方案--------------------select a.* from tb a,
(select sh,ph , max(rq) rq from tb group by sh,ph) b
where a.sh = b.sh and a.ph = b.ph and a.rq = b.rq
------解决方案--------------------SELECT *
FROM TB A
WHERE NOT EXISTS
(SELECT 1 FROM TB WHERE A.SH=SH AND A.PH=PH AND RQ> A.RQ)