我在 MySQL 数据库
中有 JSON 值条件
1->
[{"offer_id":"158","offer_start":"2017-12-17 09:21:27","offer_ends":"2017-12-17 10:21:27"},{"offer_id":"167","offer_start":"2017-12-17 12:28:57","offer_ends":"2017-12-17 12:58:57"}]
2 - >
[{"offer_id":"170","offer_start":"2018-01-17 04:26:26","offer_ends":"2018-01-17 05:11:26"},{"offer_id":"167"}]
3 - >
[{"offer_id":"170","offer_start":"2017-12-11 20:49:12","offer_ends":"2017-12-11 20:49:12"}]
3 - >
[{"offer_id":"170"}]
所以我需要使用mysql查询获得第n个 offer_ends 值,如“2017-12-11 20:49:12”
答案 0 :(得分:0)
考虑到您需要查找列名table1
的{{1}}数据。您需要获取“offer_ends”具有值offers
2017-12-11 20:49:12
获取所有记录:
SELECT JSON_CONTAINS(offers, '2017-12-11 20:49:12', '$.offer_ends')
FROM table1;
如果您愿意,可以在任何列上应用订单,然后获取前1条记录以获取最后一条记录。
答案 1 :(得分:0)
这里我有一个代码,通过使用MySQL获取所有offer_ends值 - > SELECT REPLACE(REPLACE(JSON_EXTRACT('[{“offer_id”:“23”,“offer_start”:“2017-12-11 20:49:12”,“offer_ends”:“2017-12-11 20:49:12 “},{”offer_id“:”23“,”offer_start“:”2017-12-11 20:49:12“,”offer_ends“:”2017-12-11 20:49:12“}]',' $ [*]。offer_ends'),'[',''),']','')为offer_dates
,结果是 - > “2017-12-11 20:49:12”,“2017-12-11 20:49:12”显示所有报价结束日期
所以我需要找到这样的第n个offer_ends值 - > “2017-12-11 20:49:12”
答案 2 :(得分:0)
伙计们我找到了解决方案
SELECT JSON_EXTRACT(' [{" offer_id":" 158"," offer_start":" 2018-02-21 13: 03:15"," offer_ends":" 2018-02-21 14:03:15"},{" offer_id":" 170& #34;," offer_start":" 2018-02-21 15:03:15"," offer_ends":" 2018-02-21 16 :03:15"}]',CONCAT(" $ [",JSON_LENGTH(' [{" offer_id":" 158&# 34;," offer_start":" 2018-02-21 13:03:15"," offer_ends":" 2018-02-21 14: 03:15"},{" offer_id":" 170"," offer_start":" 2018-02-21 15:03:15& #34;," offer_ends":" 2018-02-21 16:03:15"}]') - 1,"]。offer_ends" ))作为报价
谢谢你们