79312536

Date: 2024-12-27 18:27:23
Score: 0.5
Natty:
Report link

Using STRING_SPLIT will do what you want.

SELECT value AS food
     , SUM(x.count) AS count
FROM record AS x
    CROSS APPLY string_split(REPLACE(REPLACE(x.food_preference, '[', ''), ']', ''), ',') AS z
GROUP BY value;

DBFiddle

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Caleb Carl