In PostgreSQL 9.4 I have a table:
id         p_id
PK        integer
-----------------
1           1
2           1
.............
123122       2233
Is there a way to count all distinct p_id values in the table with only one query (without using subqueries). I'm free to use any window-function.
 
    