[英]mysql - Count Number of Rows returns 1 if there is no value
May I know how to count the number of staff using the count? 我可以知道如何计算使用计数的员工人数吗? From the code that I made, I am able to get the result but it will still count as 1 if there is no staff on that location. 从我制作的代码中,我能够得到结果,但如果该位置没有人员,它仍将计为1。
$sql = "SELECT mlk.lokasi, staff.staff_id, count(*) as staff_number
FROM staff RIGHT JOIN mlk on mlk.l_id=staff.l_id
GROUP BY mlk.lokasi
ORDER BY mlk.lokasi";
"SELECT mlk.lokasi, count(staff.staff_id) as staff_number FROM staff RIGHT JOIN mlk on mlk.l_id=staff.l_id GROUP BY mlk.lokasi ORDER BY mlk.lokasi";
尝试这个而不是使用*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.