You don’t want to use CORR - if you create a “food number” and assign Beef = 1, Chicken = 2 and Pasta = 3, then the correlation coefficient will tell you whether the increased cheese correlates with the increased amount of food. But “amount of food” above or below does not mean anything since you did it. Thus, do not use CORR unless your products are actually sorted in some way, like numbers.
The way statisticians talk about it is the measurement levels . In the language of a related article, MEAL_NUM is a nominal measure - or maybe an ordinal measure if the food was in order, but in any case it is really a bad idea to use correlation coefficients on it.
You probably want to find something like, "What percentage of beef dishes also have cheese?" For each ingredient, the following amount of nutrients will be indicated, as well as the amount of food and cheese it contains. The trick is that COUNT only considers non-zero values.
SELECT Other.Ingredient, COUNT(*) AS TotalMeals, COUNT(Cheese.Ingredient) AS CheesyMeals FROM table Other LEFT JOIN table Cheese ON (Cheese.Ingredient = 'Cheese' AND Cheese.Meal_Num = Other.Meal_Num) GROUP BY Other.Ingredient
Warning: returns incorrect results if you include the ingredient twice in one meal.
Edit: Turns out you are not particularly interested in cheese. You really want all pairs of “correlations”. So, we can abstract from the "Cheese" and call them only the first and second ingredients. I have added “Possible plot” to this one, which tries to act as percentage nutrition but does not give a strong result if there are very few copies of the ingredient.
SELECT First.Ingredient, Second.Ingredient, COUNT(*) AS MealsWithFirst, COUNT(First.Ingredient) AS MealsWithBoth, COUNT(First.Ingredient) / (COUNT(*) + 3) AS PossibleScore, FROM table First LEFT JOIN table Second ON (First.Meal_Num = Second.Meal_Num) GROUP BY First.Ingredient, Second.Ingredient
When sorting by invoice, this should return
PASTA CHEESE 2 2 0.400 CHEESE PASTA 3 2 0.333 BEEF CHEESE 1 1 0.250 BEEF PASTA 1 1 0.250 FISH CHEESE 1 1 0.250 FISH PASTA 1 1 0.250 CHICKEN CHEESE 1 1 0.250 PASTA BEEF 2 1 0.200 PASTA FISH 2 1 0.200 CHEESE BEEF 3 1 0.167 CHEESE FISH 3 1 0.167 CHEESE CHICKEN 3 1 0.167