1 回答
TA贡献1807条经验 获得超9个赞
您需要取消引用 json 值,并将其转换为数字,以便可以使用它进行正确的排序。您可以同时执行这两项操作,如下所示:
order by page_content ->> '$.statistics.viewCount' + 0
如果您的 MySQL 版本不支持运算符->>
,则:
order by json_extract(page_content, '$.statistics.viewCount')) + 0
DB Fiddle 上的演示- 两个查询都会产生:
| page_content |
| :--------------------------------------------------------------------------------------- |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "323810"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "529588"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "1434348"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "2176846"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "6416534"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "8088410"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "9885758"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "16058462"}} |
| {"id": "id", "etag": "edtags", "kind": "video", "statistics": {"viewCount": "26795682"}} |
- 1 回答
- 0 关注
- 131 浏览
添加回答
举报