Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
Postgresql:仅保留整数数组中的唯一值_Postgresql_Unique_Find Occurrences - Fatal编程技术网

Postgresql:仅保留整数数组中的唯一值

Postgresql:仅保留整数数组中的唯一值,postgresql,unique,find-occurrences,Postgresql,Unique,Find Occurrences,假设我有一个整数数组 1 6 6 3 3 8 4 4 它的形式总是n*(成对数字)+2(唯一数字) 是否有一种有效的方法仅保留2个唯一值(即2个单一出现) 在这里,我想得到1和8 到目前为止,我的情况如下: SELECT node_id FROM ( SELECT node_id, COUNT(*) FROM unnest(array[1, 6, 6 , 3, 3 , 8 , 4 ,4]) AS node_id GROUP BY node_id ) foo ORD

假设我有一个整数数组

1  6 6  3 3  8  4 4
它的形式总是
n*(成对数字)+2(唯一数字)

是否有一种有效的方法仅保留2个唯一值(即2个单一出现)

在这里,我想得到1和8

到目前为止,我的情况如下:

SELECT node_id 
FROM 
( SELECT node_id, COUNT(*) 
  FROM unnest(array[1,  6, 6 , 3, 3 , 8 , 4 ,4]) AS node_id 
  GROUP BY node_id 
) foo 
ORDER BY count LIMIT 2;

你很接近,我想:

SELECT node_id 
FROM (SELECT node_id, COUNT(*) 
      FROM unnest(array[1,  6, 6 , 3, 3 , 8 , 4 ,4]) AS node_id 
      GROUP BY node_id 
      HAVING count(*) = 1
     ) foo ;
如果愿意,可以使用
array\u agg()
将它们重新分组到一个数组中