L
lasmai
Unregistered / Unconfirmed
GUEST, unregistred user!
有一表T结构如下<br>ID1 ID2 DD QTY<br>A A 2007-04-01 1000<br>A A 2007-04-03 2000<br>A B 2007-04-02 3000<br>A B 2007-04-30 4000<br>B A 2007-04-06 5000<br>B B 2007-04-08 6000<br>想求得相同ID1,ID2.最后日期(DD)的数量(QTY),上面数据就是得到<br>A A 2007-04-03 2000<br>A B 2007-04-30 4000<br>B A 2007-04-06 5000<br>B B 2007-04-08 6000<br><br>我自己想到的是<br>select a.*, b.qty from (select id1, id2, max(dd) as dd from t3 group by id1, id2) a left join t b on<br>a.id1=b.id1 and a.id2=b.id2 and a.dd=b.dd<br><br>请大家帮助给出更简单的语句,谢谢