How to sum of column by depending other column in my sql?
SELECT 
t1.code,
COUNT(*) AS total_rows,
SUM(t1.data-&gt;'$.chart."21"') AS total_a
FROM yourTable AS t1
JOIN (SELECT code, MAX(updateid) AS updateid
      FROM yourTable
      GROUP BY code) AS t2 ON t1.code = t2.code
                          AND t1.updateid = t2.updateid
GROUP BY t1.code
ORDER BY t1.code;