Как запросить MySQL для подсчета значений NULL в столбце таблицы базы данных. Мой запрос в ответе всегда 0 печатать.
$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 ")->queryRow();
print_r($rawm_jan_full);
$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
пожалуйста, используйте Queryall вместо queryRow.
Вы можете использовать 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);