I have a schema like
goods_quality
( gqualityId
, GoodsId
, UnitId
, SupplierId
, quality
)
I want to get sum of quality gourp by SupplierId and GoodsId , so I do as this:
\Pkerp\Models\GoodsQuality::query()
->columns(array("SUM(quality)","*"))
->groupBy("SuplierId")
->groupBy("GoodsId")
->having("SUM(quality) > 0")
->execute();
but I got exception
Phalcon\Mvc\Model\Exception: Scanning error before 'SUM(quality) > 0...' when parsing: SELECT SUM(quality), * FROM [Pkerp\Models\GoodsQuality] GROUP BY [SUM(quality) > 0]
Why the group by field form the having() method ?
and I also try to use modelManager it's just work like this:
$this->modelsManager->createBuilder()
->columns(array("amount"=>"SUM(SG.quality)","SG.*"))
->from(array('SG'=>"\\Pkerp\\Models\\GoodsQuality"))
->groupBy("SG.SupplierId")
->groupBy("SG.GoodsId")
->having("SUM(SG.quality) > 0")
->getQuery()
->execute();
I don't know what's different?