Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

sql to criteria

I Need help. There is a table of goods There is a price table The goods have the group_id attribute. Several goods with different prices can be combined into a group. Need to under GROUP BY group_id to do sorting on price. I managed to make such a request to the database

SELECT i.group_id
, min(istock.retail) price
FROM item i
LEFT JOIN item_stock istock ON istock.item_id = i.id

WHERE i.public = 1
AND i.`status` = 'actual'
AND i.id IN(10685, 2759, 10686, 1644, 894, 7302, 7328, 6717, 8885)
GROUP BY i.group_id
ORDER BY price ASC
;

But there is no field in the model

min(istock.retail) price

Can someone help shift this request to Phalcon\Mvc\Model\Criteria



147
Accepted
answer

I apologize for such a childish question. Got some sleep and realized. can be

min(istock.retail) 

to move in ORDER BY.

SELECT i.group_id
FROM item i
LEFT JOIN item_stock istock ON istock.item_id = i.id

WHERE i.public = 1
AND i.`status` = 'actual'
AND i.id IN(10685, 2759, 10686, 1644, 894, 7302, 7328, 6717, 8885)
GROUP BY i.group_id
ORDER BY min(istock.retail) ASC
;