0

this is my mysql query . I want to convert in magento collection.

reference link https://stackoverflow.com/questions/34253461/repeat-a-result-row-multiple-times-by-value-in-row

select Item , ItemName ,  Quantity
from yourtable A
cross join (select num from numbers) b
where a.Quantity <= b.num

I tried below code but not work

$collection = Mage::getModel('sales/order_item')->getCollection()->addFieldToSelect(array('sku','qty_ordered'));

        $collection->getSelect()->joinCross(array('num' => 'new_table_qty_numbers'),array('main_table.sku','main_table.qty_ordered'))
        ->where('main_table.qty_ordered >= num.qty'); //also tried main_table.qty_ordered <= num.qty
        echo "<pre>";
        print_r($collection->getData());

1 Answer 1

0

Try this out!

$query = 'SELECT `item`,`itemname`,`qty` FROM `yourtableA` CROSS JOIN (SELECT `num` FROM `numbers`) `b` WHERE `a.qty` <= `b.num`';

$result = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($query);

Let me know if this worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.