SQLite JSON Group By – How to Group JSON Data Using a Query

group byjsonquerysqlite

I have a db whose values are as follows:img Can I call the json value of listing_id(23,27….so on) in properties column(with having row value as "listing") using a single query, I would Really Appreciate the help .enter image description here

I'm using sqlite .json extension is not available.what I'm trying to do is::group all the rows having listing_id as a single value(23,27…).is there any other way?

Best Answer

If the content of the properties column is like in your screenshot, it's easy to remove everything from the content except for the pure number IDs:

SELECT REPLACE(REPLACE(properties, '{"listing_id":', ''), '}', '') AS listing,
       *
FROM   ahoy_events;

This will give you the pure numbers from your json column as (new) column listing.

| listing | id | visit_id | ... | properties        |
|---------------------------------------------------|
| 27      | 57 | 2        | ... | {"listing_id":27} |
| 23      | 58 | 2        | ... | {"listing_id":23} |

You can then group by this value.

Was this what you were asking for?