计算COUNT(*)会导致MySQL

时间:2016-10-09 21:59:51

标签: mysql

我需要计算从MySQL查询返回的记录数。

SELECT 
    COUNT(sa.facility_hmis) AS deployed
FROM
    facility_service_area sa
GROUP BY sa.facility_hmis 

这会让我说6行作为结果,但我需要它给我一行只有数字计数行,即6

3 个答案:

答案 0 :(得分:3)

如果你需要的是计算不同facility_hmis的数量,你可以明确地做到这一点,而不计算其他任何事情:

SELECT COUNT(DISTINCT facility_hmis) FROM facility_service_area

答案 1 :(得分:3)

使用distinct

SELECT COUNT(distinct facility_hmis) AS deployed FROM facility_service_area

答案 2 :(得分:1)

将查询换入另一个// Initilize what to delete $delete_val = array('PLZ'); // Search for the array key and unset foreach($delete_val as $dv){ foreach($field as $key => $object){ $array = (array)$object; if(in_array($dv, $array, true)){ unset($field[$key]); } } } $field = array_values($field); // display $field array var_dump($field);

count()