Rainer Gauweiler wrote:
> Hello together,
> I have a table of invoices f.e. invoices (customer,invoice-nr,date). Now I
> want the recent five invoices of each customer.
> I could select all customers and select the five invoices step by step but I
> want to use only one statement. Is there a way? I tried to work with
> subselects or with the with-statement but didn't find the trick. Any ideas?
>
with recent_orders as (
select
customer,
invoice-nr,
date,
row_number() over (partition by customer, order by date desc) as rn
from
invoices
)
select customer, invoice-nr,date
from recent_orders
where rn <= 5;



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
[url]http://www.newsfeeds.com[/url] - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----