$rech=$_bdd->query('select distinct num_carte,type_seance,nom_module from absence,seance,absence_justification,module where absence.id_absence=absence_justification.id_absence AND absence.id_seance=seance.id_seance AND seance.id_module=module.id_module GROUP BY num_carte,type_seance,nom_module having count(jus_admin="non")>4 ');
I have this code in my PHP website and when I use the having count , I found that the count doesn't compare jus_admin="non"
. It ignore the condition so he just count the number of jus_admin and return the result I didn't understand why he ignore the condition !!!!!!!
count()
counts the number of non-NULL values. Booleans in MySQL are typically 0 or 1.
So, your logic:
having count(jus_admin = 'non') > 4
only returns NULL
if jus_admin
is NULL
. This is equivalent to:
having count(jus_admin) > 4
Which, if it never takes on NULL
, would be the same as:
having count(*) > 4
I think you want sum()
rather than count()
:
having sum(jus_admin = 'non') > 4
This will require at least five 'non'
values for each group that is returned.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.