I have mysql table like this which contain id and json type column:
id | value |
---|---|
1 | {"sys": "20", "dia": "110"} |
2 | {"bpm": "200"} |
3 | {"bpm": "123", "sys": "1", "dia": ""} |
Now, I want to have a MySQL query to which data should be as below in which id, val1 will contain keys of the json data and val2 will contain values of respective keys :
id | val1 | val2 |
---|---|---|
1 | sys | 20 |
1 | dia | 110 |
2 | bpm | 200 |
3 | bpm | 123 |
3 | sys | 1 |
3 | dia |
Note : I am using MySQL 5.7 version and the keys inside the JSON object are not fixed. It can be any number.
I want to know how I can achieve this using MySQL query
Thanks in Advance!!!
id
,vital_name
, andvalue
columns. Notice you can also add timestamps or other attributes to the vitals. PLEASE don't put JSON in your table columns, at least not for data you ever want MySQL to manipulate.