sql - Get the first 10 rows for each group -
i have 3 tables:
customer(idcustomer, name) product(idproduct, product) order(idproduct, idcustomer, nborders) so order table stores how many times customer has ordered product.
i need view this:
toporder(name, product, nbcommands) but want 10 products each customer, ones ordered , can't figure out.
the dense_rank window function should doctor prescribed:
create view toporder select name, product, nborders   (select name, product, nborders,                dense_rank() on (partition o.idcustomer                                   order nborders desc) rk           customer c         join   orders o on c.idcustomer = o.idcustomer         join   product p on p.idproduct = o.idproduct        ) t  rk <= 10 
Comments
Post a Comment