Back to questions

Fill Missing Client Data Accenture SQL Interview Question

Fill Missing Client Data

Accenture SQL Interview Question

When accessing Accenture's retailer client's database, you observe that the category column in products table contains null values.

Write a query that returns the updated product table with all the category values filled in, taking into consideration the assumption that the first product in each category will always have a defined category value.

Assumptions:

  • Each category is expected to be listed only once in the column and products within the same category should be grouped together based on sequential product IDs.
  • The first product in each category will always have a defined category value.
    • For instance, the category for product ID 1 is 'Shoes', then the subsequent product IDs 2 and 3 will be categorised as 'Shoes'.
    • Similarly, product ID 4 is 'Jeans', then the following product ID 5 is categorised as 'Jeans' category, and so forth.

Effective April 16, 2023, the question, assumptions, solution and hints were revised.

Table

Column NameType
product_idinteger
categoryvarchar
namevarchar

Example Input

product_idcategoryname
1ShoesSperry Boat Shoe
2Adidas Stan Smith
3Vans Authentic
4JeansLevi 511
5Wrangler Straight Fit
6ShirtsLacoste Classic Polo
7Nautica Linen Shirt

Example Output

product_idcategoryname
1ShoesSperry Boat Shoe
2ShoesAdidas Stan Smith
3ShoesVans Authentic
4JeansLevi 511
5JeansWrangler Straight Fit
6ShirtsLacoste Classic Polo
7ShirtsNautica Linen Shirt

Explanation

Shoes will replace all values below the product Sperry Boat Shoe until Jeans appears. Similarly, Jeans will replace s for the product Wrangler Straight Fit, and so on.

The dataset you are querying against may have different input & output - this is just an example!

Input

Output