1 回答

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
您需要取消引用 json 值,并將其轉(zhuǎn)換為數(shù)字,以便可以使用它進(jìn)行正確的排序。您可以同時(shí)執(zhí)行這兩項(xiàng)操作,如下所示:
order by page_content ->> '$.statistics.viewCount' + 0
如果您的 MySQL 版本不支持運(yùn)算符->>
,則:
order by json_extract(page_content, '$.statistics.viewCount')) + 0
DB Fiddle 上的演示- 兩個(gè)查詢都會(huì)產(chǎn)生:
| 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 關(guān)注
- 194 瀏覽
添加回答
舉報(bào)