Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张表,我在其中存储客户 ID 和他们登录的日期。
Cust_ID REC_DATE 773209 11/5/2013 4:30:52 PM 817265 11/5/2013 4:31:19 PM
等等
我怎样才能看到每个客户的最新两条记录?
您可以使用分析功能row_number():
row_number()
select t.* from (select t.*, row_number() over (partition by cust_id order by rec_date desc) as seqnum from yourtable t ) t where seqnum <= 2;