I have the following table:
CREATE TABLE Kittens (
k_id INTEGER PRIMARY KEY AUTOINCREMENT,
human_name text,
tags json
);
With this data
INSERT INTO Kittens (human_name, tags) VALUES ("Charles",'["fiendish", "fluffy", "quiet", "discerning", "catlike"]');
INSERT INTO Kittens (human_name, tags) VALUES ("Tails",'["fluffy", "loud","catlike"]');
INSERT INTO Kittens (human_name, tags) VALUES ("Mittens",'["fluffy","regal","catlike"]');
I'd like to aggregate the common kitten tags, and I believe this requires the json_group_array function, which I've read about here:
- https://www.sqlite.org/json1.html#jarray
- http://sqlite.1065341.n5.nabble.com/json-group-array-td87148.html
However, this doesn't seem to be unrolling or aggregating the tags as I would expect, just list the lists consecutively.
sqlite> select json_group_array(tags) from Kittens;
["[\"fiendish\", \"fluffy\", \"quiet\", \"discerning\", \"catlike\"]","[\"fluffy\", \"loud\",\"catlike\"]","[\"fluffy\",\"regal\",\"catlike\"]"]
Any guidance on what this query should look like? Seeking something more like:
tag_array
catlike
catlike
catlike
discerning
fiendish
fluffy
fluffy
fluffy
loud
quiet
regal
And ultimately, with an aggregation:
tag_array count(*)
fluffy 3
catlike 3
fiendish 1
discerning 1
loud 1
regal 1
quiet 1