Answer the question
In order to leave comments, you need to log in
How to write nested sub request (php yii)?
It is not possible to display the sums of already summed values from the table, I think that the matter is in the query. It is necessary to write such a query with a nested subquery so that it would output summarized and display non-repeating values
foreach ($months as $key => $m)
{
if ($key > $max_month) break;
$k = sprintf('%02.0d', ($key + 1));
$fields .= ', '."\n SUM(".$m.'.active_count) as '.$m.'_active_count, SUM('.$m.'.active_sum) as '.$m.'_active_sum,
'."\n SUM(".$m.'.realized_count) as '.$m.'_realized_count, SUM('.$m.'.realized_sum) as '.$m.'_realized_sum';
$joins .= "\n"."LEFT JOIN tbl_report ".$m." ON ".$m.".date > '".$year."-".$k."-01 00:00:00' AND
".$m.".date < '".$year."-".$k."-31 24:59:59' AND
".$m.".fio = all_months.fio ";
}
$query = "SELECT DISTINCT ".$fields."
FROM tbl_report
".$joins."
WHERE all_months.date > '".$year."-01-01 00:00:00' AND all_months.date < '".$year."-12-31 24:59:59'";
//echo $query;
$data['summary'] = Yii::app()->db->createCommand($query)->queryRow();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question