をコマンドにIFNULL例外を追加し、私は、コマンドを作成してきたし、それが正常に動作しますが、私はIFNULL例外を追加するとき、それはカンマを追加し、私は何の答えは私のコードが存在しない多くのことを検索:yii2:
public function actionTotal($id)
{
$query1 = new Query;
$query1 ->select(' sum(patient_services.price) price ,
sum(IFNULL(receipts.price,0)) receipts')
->from('patient_services')
->leftJoin('receipts', 'patient_services.patient_id = receipts.patient_id')
->where('patient_services.patient_id=:id', array(':id'=>$id));
$command1 = $query1->createCommand();
$price = $command1->queryAll();
echo Json::encode($price);
}
Iそれを試してみてください...セレクトコードはコンマを持っているとidon'tはあなたのコードでは、それ
SELECT sum(patient_services.price) price, sum(IFNULL(receipts.price, `0))` AS `receipts` FROM `patient_services` LEFT JOIN `receipts` ON patient_services.patient_id = receipts.patient_id WHERE patient_services.patient_id=2
私は質問を更新しました:( –
私は自分のansを編集しました。あなたはあなたのselectステートメントに括弧[]を入れる必要があります。 –