SELECt MAX(id) id, po_nbrFROM tempGROUP BY po_nbr
要获得关联的日期,您可以这样做(请注意,这意味着需要一个顺序编号):
SELECt temp.id, temp.po_nbr, temp.crt_tsFROM temp INNER JOIN ( SELECt MAX(id) id FROM temp GROUP BY po_nbr ) latest ON latest.id = temp.id
如果没有序列号,它将是:
SELECt MAX(temp.id) id, temp.po_nbr, temp.crt_tsFROM temp INNER JOIN ( SELECt MAX(crt_ts) crt_ts, po_nbr FROM temp i GROUP BY po_nbr ) latest ON latest.crt_ts = temp.crt_ts AND latest.po_nbr = temp.po_nbrGROUP BY temp.po_nbr, temp.crt_ts
GROUP BY如果可以保证每个
po_nbr组没有两个相等的日期,则可以忽略。
在上一个查询中建立索引
crt_ts并提供
po_nbr帮助,最好创建一个组合索引。



