Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL-在GROUP BY在场的情况下删除JSON_ARRAYAGG中的重复结果_Mysql_Sql_Arrays_Json_Database - Fatal编程技术网

MySQL-在GROUP BY在场的情况下删除JSON_ARRAYAGG中的重复结果

MySQL-在GROUP BY在场的情况下删除JSON_ARRAYAGG中的重复结果,mysql,sql,arrays,json,database,Mysql,Sql,Arrays,Json,Database,我有疑问: SELECT id, JSON_ARRAYAGG(url) AS urlLinks FROM links WHERE id=832781 GROUP BY id; 此查询的结果与列urlinks中的相同图像URL重复: ["index.html", "index.html", "index.html", "index.html", "index.html"] 我怎样才能只留下唯一的图像URL ["index.html"] 无法从请求中删除分组依据 JSON_ARRAYAGG()

我有疑问:

SELECT id, JSON_ARRAYAGG(url) AS urlLinks
FROM links
WHERE id=832781
GROUP BY id;
此查询的结果与列
urlinks
中的相同图像URL重复:

["index.html", "index.html", "index.html", "index.html", "index.html"]
我怎样才能只留下唯一的图像URL

["index.html"]
无法从请求中删除分组依据

JSON_ARRAYAGG()
不支持
DISTINCT
。您可以在子查询中
选择DISTINCT
,然后聚合:

SELECT id, JSON_ARRAYAGG(url) AS urlLinks
FROM (SELECT DISTINCT id, url from links) l
WHERE id=832781
GROUP BY id;

WITH links AS (
    SELECT 832781 id, 'index.html' url
    UNION ALL SELECT 832781, 'index.html'
    UNION ALL SELECT 832781, 'page.html'
)
SELECT id, JSON_ARRAYAGG(url) AS urlLinks
FROM (SELECT DISTINCT id, url from links) l
WHERE id=832781
GROUP BY id;
id | urlLinks -----: | :-------------------------- 832781 |[“index.html”、“page.html”] id | urlLinks -----: | :-------------------------- 832781 | ["index.html", "page.html"]