-- 1. Create the products table
CREATE TABLE products (
    product_id INT PRIMARY KEY,
    category VARCHAR(50),
    name VARCHAR(50)
);

-- 2. Insert the sample data (with missing category fields)
INSERT INTO products (product_id, category, name) VALUES
(1, 'Electronics', 'Laptop'),
(2, NULL, 'Tablet'),
(3, NULL, 'Smartphone'),
(4, 'Clothing', 'T-Shirt'),
(5, NULL, 'Jeans'),
(6, NULL, 'Sneakers');

with ct as (
select *,sum(case when  category is not null then 1 else 0 end)
        over(order by product_id)
    as sum_flg
    from products
)
select product_id, max(category) over(partition by sum_flg) as category, name
from ct

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: