This project processes and analyzes nutritional data from the FDC (Food Data Central) API. It involves setting up a MySQL environment with appropriate tables, loading data, and executing SQL scripts for data aggregation and analysis.
Aggregation Table/: Scripts to generate aggregated summary tables.Analysis/: SQL scripts for FDC data analysis.Installation/: SQL scripts for table creation and data loading.Procedures/: SQL stored procedures serve as a pipeline that transforms raw tables into aggregated tables.
-
Extract the data
Download the dataset from the USDA FDC website:
FDC CSV Dataset – 2025-04-24Extract the
fdc.zipfile into this directory:C:/ProgramData/MySQL/MySQL Server X.X/Uploads/. This directory should contain the CSV files to be loaded into MySQL. -
Create database tables
Run thecreate_fdc_tables.sqlscript in theInstallation/folder to create the necessary database schema. -
Load the data
Execute theload_fdc_data.sqlscript to import the extracted CSV data into MySQL. -
Create aggregated tables
Run the scripts in theAggregation Tables/folder:aggr_food_by_nutrient.sqlaggr_food_by_energy_kcal.sql
-
Create stored procedures
Execute the following scripts from theProcedures/folder:aggregate_food_by_nutrient.sqlaggregate_food_by_energy_in_kcal.sql
-
Run backfill
Call the stored procedures to perform the backfill:CALL aggregate_food_by_nutrient(); CALL aggregate_food_by_energy_in_kcal();
The Analysis/ folder contains advanced SQL scripts for evaluating and comparing food items based on their nutrient composition. These queries provide deeper insights after the data has been processed.
- Top food by carbohydrate amount – Lists foods with the highest carbohydrate content.
- Top food by fat amount – Lists foods with the highest fat content.
- Top food by protein amount – Lists foods with the highest protein content.
- Similarity energy ratio (Cosine Similarity) – Compares food items based on energy ratios using cosine similarity.
- Similarity energy ratio (Euclidean Distance) – Compares food items based on energy ratios using Euclidean distance.
These scripts are useful for nutrient comparison, food clustering, or building recommendation systems.