my table contains a value
json-column. The format is following:
{
"id":"string",
"user":int,
"history":{
"unixtimestamp":{
"progress":"string",
"editorId":int
},
"unixtimestamp":{
"progress":"string",
"editorId":int
},
...
}
}
I try to get all rows where the unixtimestamp contains a key which is between a given date. I can get an array set of the keys by selecting JSON_KEYS(´value', '$.history')
. But I can't find a solution how to filter this.
Thanks for help!
my table contains a value
json-column. The format is following:
{
"id":"string",
"user":int,
"history":{
"unixtimestamp":{
"progress":"string",
"editorId":int
},
"unixtimestamp":{
"progress":"string",
"editorId":int
},
...
}
}
I try to get all rows where the unixtimestamp contains a key which is between a given date. I can get an array set of the keys by selecting JSON_KEYS(´value', '$.history')
. But I can't find a solution how to filter this.
Thanks for help!
Share Improve this question edited 2 days ago Dale K 27.3k15 gold badges57 silver badges83 bronze badges asked 2 days ago KriZaKriZa 233 bronze badges New contributor KriZa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1- 1 Help us help you - share some sample data and the result you're trying to get for it. – Mureinik Commented 2 days ago
1 Answer
Reset to default 1JSON_KEYS(t.value, '$.history')
to get the keys from history.JSON_TABLE
to flatten the array of keys.CAST(j.t_key AS UNSIGNED)
to convert to number and allow filtering.
SELECT
DISTINCT CAST(value AS CHAR)
FROM
sample_table AS t
JOIN JSON_TABLE(
JSON_KEYS(t.value, '$.history'),
'$[*]' COLUMNS (
t_key VARCHAR(20) PATH '$'
)
) AS j ON TRUE
WHERE
CAST(j.t_key AS UNSIGNED)
BETWEEN 1737100000 AND 1737290000
dbfiddle