CREATE TABLE test_table (a json);
INSERT INTO test_table (a) VALUES ('{"id":"90909","records":[{"name":"john","date":"2016-06-16"},{"name":"koiy","date":"2016-08-26"},{"name":"koiy","date":"2016-01-06"}]}');
WITH cte as (
SELECT json_array_elements(a->'records') as record FROM test_table
)
SELECT record
FROM cte
ORDER BY (record->>'date')::date DESC
LIMIT 1;
->
+-------------------------------------+
| record |
|-------------------------------------|
| {"name":"koiy","date":"2016-08-26"} |
+-------------------------------------+
SELECT 1
Time: 0.003s
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…