如何查询MySQL来计算' NULL'数据库表列中的值。我的回复查询总是0打印。
igraph
答案 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);