有没有办法计算多个不同的值?
Is there a way to count a number of distinct values?
在 PostgreSQL 9.4 中我有一个 table:
id p_id
PK integer
-----------------
1 1
2 1
.............
123122 2233
有没有一种方法可以仅通过一个查询(而不使用子查询)来计算 table 中所有不同的 p_id
值。我可以自由使用任何 window-函数。
可以在count
函数中使用distinct
修饰符:
SELECT COUNT(DISTINCT p_id) FROM mytable
在 PostgreSQL 9.4 中我有一个 table:
id p_id
PK integer
-----------------
1 1
2 1
.............
123122 2233
有没有一种方法可以仅通过一个查询(而不使用子查询)来计算 table 中所有不同的 p_id
值。我可以自由使用任何 window-函数。
可以在count
函数中使用distinct
修饰符:
SELECT COUNT(DISTINCT p_id) FROM mytable