I have the following JSON-File
in a MYSQL
Database:
[
{
"order" : 0,
"value" : 0.168257
},
{
"order" : 0.031250,
"value" : 0.002387
},
{
"order" : 0.062500,
"value" : 0.002367
},
{
"order" : 0.093750,
"value" : 0.002365
},
{
"order" : 0.125000,
"value" : 0.002369
},
{
"order" : 0.156250,
"value" : 0.002384
},
{
"order" : 0.187500,
"value" : 0.002403
}
]
I would like to Query and get the result for "order"=0.156250 I use the following Query:
JSON_EXTRACT(jsonColumn,'$.order') ... WHERE JSON_EXTRACT(jsonColumn,'$.order') = 0.156250
It is not working. I can only select the Column by doing the following:
Select JSON_EXTRACT(jsonColumn,'$[5].order')
Can somebody tell me how to select the Column without giving the index
to the Select statement?
Thanks!
You need to convert this to json_table
first before filtering
select *
from
test t1
cross join
json_table(t1.jsonColumn,
"$[*]"
columns(
`Order` numeric(9,6) path "$.order",
`Value` numeric(9,6) path "$.value"
)
) t2
where t2.Order = 0.156250
see dbfiddle
for mySQL
versions 5.7
select
*
from test t1
cross join (
select 1 as col1 union
select 2 union
select 3 union
select 4 union
select 5 union
select 6
) t2
where json_extract(t1.jsonColumn, concat('$[', t2.col1, '].order')) = 0.156250;
see dbfiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.