Note:
All of these can be done with some jq or python scripting. This use case is for someone more familiar with SQL than programming.
This example JSON containing users, friends and hobbies is converted to set of tables with corresponding insert statements as below
Execute the generated SQL here SQL
select friend_count, u.name, u.city from
tbl_users u inner join
(select count(*) as friend_count, tbl_users_fk from tbl_users_friends group by tbl_users_fk) f
on u.tbl_users_pk=f.tbl_users_fk order by friend_count desc, name, city;
select count(*) as hobbies_count, hobbies from tbl_users_friends_hobbies group by hobbies order by hobbies_count desc;