如何查询MySQL以计算数据库字段中的NULL值?

时间:2018-05-04 09:36:28

标签: php mysql memsql

如何查询MySQL来计算' NULL'数据库表列中的值。我的回复查询总是0打印。

igraph

3 个答案:

答案 0 :(得分:1)

$rawm_jan_full=Yii::app()->db->createCommand("SELECT COUNT(case when trainings_id is null then 1 else trainings_id end ) AS trail_list from children WHERE MONTH(timestamp) = '1' AND YEAR(timestamp) ='".$previous_year."' AND trainings_id IS NULL ")->queryRow();

 Replace COUNT(trainings_id )  with    COUNT(case when trainings_id is null then 1 else trainings_id end ) in order to include null in your count result

答案 1 :(得分:0)

请使用Queryall而不是queryRow。

答案 2 :(得分:0)

您可以使用Queryall

$rawm_jan_full=Yii::app()->db->createCommand("SELECT COUNT(trainings_id) AS trail_list from children WHERE MONTH(timestamp) = '1' AND YEAR(timestamp) ='".$previous_year."' AND trainings_id IS NULL ")->Queryall();

print_r($rawm_jan_full);