I am using the following query in Active Record:
$consumption = PowerReading::find()
->select(['DATE_FORMAT( date_on, "%m-%Y" ) AS MONTH', 'SUM( active_power )'])
->where(['receiving_station' => 'ARSS'])
->groupBy('DATE_FORMAT( date_on, "%m-%Y" )')
->all();
The SQL getting generated is:
SELECT DATE_FORMAT( date_on, "%m-%Y" ) AS MONTH, SUM( active_power ) FROM `power_reading` WHERE `receiving_station`='ARSS' GROUP BY DATE_FORMAT( date_on, `"%m-%Y" )`
As can be noticed, there is a bug in the generated GROUP BY statement. There is an extra ‘`’ in front of %m. Where have I gone wrong!?