FROM jemp> WHERE JSON_EXTRACT(c, "$.id") > 1> ORDER BY JSON_EXTRACT(c, "$.name");+-------------------------------+-----------+----..._mysql对json类型数据的查询">
当前位置:   article > 正文

mysql json类型 查询_mysql查询JSON类型数据

mysql对json类型数据的查询

获取json字段内容mysql> SELECT c, JSON_EXTRACT(c, "$.id"), g

> FROM jemp

> WHERE JSON_EXTRACT(c, "$.id") > 1

> ORDER BY JSON_EXTRACT(c, "$.name");

+-------------------------------+-----------+------+

| c | c->"$.id" | g |

+-------------------------------+-----------+------+

| {"id": "3", "name": "Barney"} | "3" | 3 |

| {"id": "4", "name": "Betty"} | "4" | 4 |

| {"id": "2", "name": "Wilma"} | "2" | 2 |

+-------------------------------+-----------+------+

3 rows in set (0.00 sec)

mysql> SELECT c, c->"$.id", g

> FROM jemp

> WHERE c->"$.id" > 1

> ORDER BY c->"$.name";

+-------------------------------+-----------+------+

| c | c->"$.id" | g |

+-------------------------------+-----------+------+

| {"id": "3", "name": "Barney"} | "3" | 3 |

| {"id": "4", "name": "Betty"} | "4" | 4 |

| {"id": "2", "name": "Wilma"} | "2" | 2 |

+-------------------------------+-----------+------+

3 rows in set (0.00 sec)

mysql> SELECT c, c->"$.id", g, n

> FROM jemp

> WHERE JSON_EXTRACT(c, "$.id") > 1

> ORDER BY c->"$.name";

+-------------------------------+-----------+------+------+

| c | c->"$.id" | g | n |

+-------------------------------+-----------+------+------+

| {"id": "3", "name": "Barney"} | "3" | 3 | NULL |

| {"id": "4", "name": "Betty"} | "4" | 4 | 1 |

| {"id": "2", "name": "Wilma"} | "2" | 2 | NULL |

+-------------------------------+-----------+------+------+

3 rows in set (0.00 sec)

mysql> DELETE FROM jemp WHERE c->"$.id" = "4";

Query OK, 1 row affected (0.04 sec)

mysql> SELECT c, c->"$.id", g, n

> FROM jemp

> WHERE JSON_EXTRACT(c, "$.id") > 1

> ORDER BY c->"$.name";

+-------------------------------+-----------+------+------+

| c | c->"$.id" | g | n |

+-------------------------------+-----------+------+------+

| {"id": "3", "name": "Barney"} | "3" | 3 | NULL |

| {"id": "2", "name": "Wilma"} | "2" | 2 | NULL |

+-------------------------------+-----------+------+------+

2 rows in set (0.00 sec)

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/988975
推荐阅读
相关标签
  

闽ICP备14008679号