I'm having difficulties counting how many times it finds a new personnel_id in table planning but ignoring if it finds the same personnel_id a second time.
Exemple personnel_id 24 is on building A and building B next week but count only as 1 because this is the same person.
In the end I would do something like $result = $totalpersonnel_id_tablepersonnel - $totalpersonnel_id_tableplanning
and it would give me a number like 7 meaning 7 employees has no building affected.
I think this is the correct query for what I want:
$test=mysql_query("SELECT COUNT(DISTINCT personnel_id) AS numberpid
FROM planning WHERE personnel_id!='' GROUP BY personnel_id HAVING
COUNT(personnel_id) > 1");
I don't find how to get the sum from this query.
if personnel_id!='' mean NOT NULL use personnel_id IS NOT NULL instead and having use numberpid > 1 so query after edited below
SELECT COUNT(DISTINCT personnel_id) AS numberpid
FROM planning WHERE personnel_id IS NOT NULL
GROUP BY personnel_id
HAVING numberpid > 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With