title: mysql + all numbers from one field to Sum
body: <p>Is it possible to sum the digits in a string and sort by that?</p>
  
  <pre><code>Example values: 19, 21
  19 Should be transformed to 10. Explanation: 1+9=10
  21 Should be transformed to  3. Explanation: 2+1= 3
  </code></pre>
  
  <p>After calculating these results, the table needs to be sorted by the resulting values (using <code>SORT BY</code>).</p>
  
  <p>Originally, I have those values stored as JSON array, so it's <code>["1","9"]</code> and <code>["2","1"]</code>, and in order to parse the JSON I'm using replace as follows:</p>
  
  <pre><code>REPLACE(REPLACE(REPLACE(item_qty, '["', ''),  '"]', ''), '","', '')
  </code></pre>