SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table products ( product_id int, name varchar(64) ); insert into products values (1, 'Product 1'), (2, 'Product 2'); create table sales ( customer_id int, product_id int ); insert into sales values (1, 2), (1, 2), (1, 1), (2, 2), (2, 1), (2, 1); select customer_id, name, rank() over (partition by customer_id order by COUNT(product_id) DESC) from sales join products using (product_id)

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear