Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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 如何在Postgres中从表中获取不同的值_Postgresql_Psql - Fatal编程技术网

Postgresql 如何在Postgres中从表中获取不同的值

Postgresql 如何在Postgres中从表中获取不同的值,postgresql,psql,Postgresql,Psql,我有一个包含20列的表,我喜欢得到每列的不同值 所以如果我有 A B C D .... ---------- z c c d z f c f a c f d z c c d b f b d z c a d 我想回去 {'A':[z,A,b], “B”:[c,f], ‘C’:[C,f,b,a] “D”:[D,f] .... } 查询结果如何?也许您需要 SELECT array_agg(DISTINCT a) a, array_

我有一个包含20列的表,我喜欢得到每列的不同值

所以如果我有

A  B  C  D ....
----------
z  c  c  d 
z  f  c  f 
a  c  f  d 
z  c  c  d 
b  f  b  d 
z  c  a  d 
我想回去

{'A':[z,A,b], “B”:[c,f], ‘C’:[C,f,b,a] “D”:[D,f] .... } 查询结果如何?

也许您需要

SELECT array_agg(DISTINCT a) a,
       array_agg(DISTINCT b) b,
       array_agg(DISTINCT c) c,
       array_agg(DISTINCT d) d
FROM test;
?


恐怕你得问4个问题哪个标签错了?