Database finding data
I think you want something like this,

SELECT pid, count(DISTINCT cid) AS "number_of_customers" 
FROM table
WHERE PTIME &gt;= DATE '2017-10-01'
  AND PTIME &lt; DATE '2017-11-01'
GROUP BY pid
HAVING count(DISTINCT cid) &gt; 0;