Generate Shopping List from Recipes

Quick Overview

Combine three recipe tables of ingredient lines into one shopping list that gives each ingredient's total mass in grams, matching names case-insensitively and counting duplicate rows. It tests stacking tables in SQL without losing repeated rows, grouping on a normalized key, and producing a deterministic sorted result.

Generate Shopping List from Recipes

Company: Kroger

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Three recipes are stored in the tables `recipe1`, `recipe2` and `recipe3`. Each row is one ingredient line with its mass in grams. Combine the three recipes into a single shopping list that returns each unique ingredient and its total mass summed across all three tables. Duplicate rows within a single table are also summed, and ingredient names are matched case-insensitively. ```hint Watch the combine step Check what happens to two identical rows when you stack the three tables into one result. ``` ### Input Table(s) Tables `recipe1`, `recipe2` and `recipe3` share the same schema: | Column | Type | Meaning | |---|---|---| | ingredient | VARCHAR(100) | Ingredient name. Spelling may differ in case between rows, for example `Flour` and `flour`. | | mass | DECIMAL(10,2) | Mass of that ingredient line in grams, 0 or more. | None of the tables has a primary key. The same row can appear more than once in one table, and the same ingredient can appear in one, two or all three tables. ### Output Contract | Column | Type | Meaning | |---|---|---| | ingredient | VARCHAR | The ingredient name in lowercase. | | total_mass | DECIMAL | Sum of `mass` over every row of all three tables whose name matches this ingredient, ignoring case. | One row per ingredient. Order the rows by `ingredient` ascending. The lowercase names are unique, so this ordering is unique. `total_mass` keeps the two decimals of the input and needs no extra rounding. ### Example `recipe1`: | ingredient | mass | |---|---| | Flour | 500.00 | | Sugar | 100.00 | | eggs | 120.00 | `recipe2`: | ingredient | mass | |---|---| | flour | 250.00 | | Butter | 200.00 | | Butter | 200.00 | `recipe3`: | ingredient | mass | |---|---| | SUGAR | 50.50 | | Butter | 200.00 | | Salt | 5.00 | Expected output: | ingredient | total_mass | |---|---| | butter | 600.00 | | eggs | 120.00 | | flour | 750.00 | | salt | 5.00 | | sugar | 150.50 | `Butter, 200.00` appears twice in `recipe2` and once in `recipe3`, and all three rows count, so butter totals 600.00. `Flour` and `flour` are the same ingredient (500.00 + 250.00), and so are `Sugar` and `SUGAR` (100.00 + 50.50). Eggs and salt appear in only one table each. ### Constraints and Clarifications - An ingredient may appear in one, two or all three tables. - Names are compared after converting to lowercase. No other normalization applies, so `olive oil` and `olive oil` (two spaces) are different ingredients. - `mass` is non-negative. - Assume no row has a NULL `ingredient` or a NULL `mass`. - Every row counts, including exact duplicates within one table and identical rows in different tables.

Overview: Combine three recipe tables of ingredient lines into one shopping list that gives each ingredient's total mass in grams, matching names case-insensitively and counting duplicate rows. It tests stacking tables in SQL without losing repeated rows, grouping on a normalized key, and producing a deterministic sorted result.

Kroger logo
Kroger
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Three recipes are stored in the tables recipe1, recipe2 and recipe3. Each row is one ingredient line with its mass in grams. Combine the three recipes into a single shopping list that returns each unique ingredient and its total mass summed across all three tables. Duplicate rows within a single table are also summed, and ingredient names are matched case-insensitively.

Input Table(s)

Tables recipe1, recipe2 and recipe3 share the same schema:

ColumnTypeMeaning
ingredientVARCHAR(100)Ingredient name. Spelling may differ in case between rows, for example Flour and flour.
massDECIMAL(10,2)Mass of that ingredient line in grams, 0 or more.

None of the tables has a primary key. The same row can appear more than once in one table, and the same ingredient can appear in one, two or all three tables.

Output Contract

ColumnTypeMeaning
ingredientVARCHARThe ingredient name in lowercase.
total_massDECIMALSum of mass over every row of all three tables whose name matches this ingredient, ignoring case.

One row per ingredient. Order the rows by ingredient ascending. The lowercase names are unique, so this ordering is unique. total_mass keeps the two decimals of the input and needs no extra rounding.

Example

recipe1:

ingredientmass
Flour500.00
Sugar100.00
eggs120.00

recipe2:

ingredientmass
flour250.00
Butter200.00
Butter200.00

recipe3:

ingredientmass
SUGAR50.50
Butter200.00
Salt5.00

Expected output:

ingredienttotal_mass
butter600.00
eggs120.00
flour750.00
salt5.00
sugar150.50

Butter, 200.00 appears twice in recipe2 and once in recipe3, and all three rows count, so butter totals 600.00. Flour and flour are the same ingredient (500.00 + 250.00), and so are Sugar and SUGAR (100.00 + 50.50). Eggs and salt appear in only one table each.

Constraints and Clarifications

  • An ingredient may appear in one, two or all three tables.
  • Names are compared after converting to lowercase. No other normalization applies, so olive oil and olive oil (two spaces) are different ingredients.
  • mass is non-negative.
  • Assume no row has a NULL ingredient or a NULL mass .
  • Every row counts, including exact duplicates within one table and identical rows in different tables.