msyql json 数组去除重复数据

 

SET @json = '["a", "b", "b", "a", "c"]';
SELECT Json_arrayagg(dt.val) AS unq_json_array
FROM (SELECT DISTINCT Json_extract(@json, Concat('$[', seq.n, ']')) AS val
FROM (SELECT 0 AS n UNION ALL SELECT 1 UNION ALL
SELECT 2 UNION ALL SELECT 3 UNION ALL
SELECT 4 UNION ALL SELECT 5 UNION ALL
SELECT 6 UNION ALL SELECT 7 UNION ALL
SELECT 8 UNION ALL SELECT 9) AS seq) AS dt
WHERE dt.val IS NOT NULL;

 

posted @ 2020-11-17 09:49  开顺  阅读(2272)  评论(1编辑  收藏  举报