Skip to content
Advertisement

Count json tags in sql

I have this json strings

And know i want the following output

I wanted to do this with a sql query. If you know how to do this, thanks in advance!

Advertisement

Answer

If you’re not using MySQL 8, this is a bit more complicated. First you have to find a path to a name element that has the value phone (or fixkit); then you can replace name in that path with count and extract the count field from that path; these values can then be summed:

Output:

Demo on dbfiddle

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement