How to use expression values in where condition?












0















How to do that in magento model way



Select sum(qty + product_id - any_other_columns) as total from table2  where total>10;









share|improve this question





























    0















    How to do that in magento model way



    Select sum(qty + product_id - any_other_columns) as total from table2  where total>10;









    share|improve this question



























      0












      0








      0


      1






      How to do that in magento model way



      Select sum(qty + product_id - any_other_columns) as total from table2  where total>10;









      share|improve this question
















      How to do that in magento model way



      Select sum(qty + product_id - any_other_columns) as total from table2  where total>10;






      model eav query






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 35 mins ago









      Teja Bhagavan Kollepara

      2,94841847




      2,94841847










      asked May 13 '16 at 9:41









      Vipan Kumar ParjapatiVipan Kumar Parjapati

      32




      32






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Its a strange query you want to run, but this is how you do it:



          $collection = Mage::getModel('catalog/product')->getCollection();
          $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
          $collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
          $collection->getSelect()->having('total > 10');





          share|improve this answer































            0














            Here is the example how to use Direct mysql in Magento



            /**
            * Get the resource model
            */
            $resource = Mage::getSingleton('core/resource');

            /**
            * Retrieve the write connection
            */
            $writeConnection = $resource->getConnection('core_write');

            /**
            * Retrieve our table name
            */
            $table = $resource->getTableName('catalog/product');

            /**
            * Set the product ID
            */
            $productId = 44;

            /**
            * Set the new SKU
            * It is assumed that you are hard coding the new SKU in
            * If the input is not dynamic, consider using the
            * Varien_Db_Select object to insert data
            */
            $newSku = 'new-sku';

            $query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
            . (int)$productId;

            /**
            * Execute the query
            */
            $writeConnection->query($query);


            For More see here.



            Another way



            $_products = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect(array('name', 'product_url', 'small_image'))
            ->addAttributeToFilter('sku', array('like' => 'UX%'))
            ->load();


            For more detail see here.






            share|improve this answer
























            • you didn't read my question i think

              – Vipan Kumar Parjapati
              May 13 '16 at 10:29











            • I have read your question and these are just examples now what do you want ?

              – Arunendra
              May 13 '16 at 10:34











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f115275%2fhow-to-use-expression-values-in-where-condition%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Its a strange query you want to run, but this is how you do it:



            $collection = Mage::getModel('catalog/product')->getCollection();
            $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
            $collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
            $collection->getSelect()->having('total > 10');





            share|improve this answer




























              0














              Its a strange query you want to run, but this is how you do it:



              $collection = Mage::getModel('catalog/product')->getCollection();
              $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
              $collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
              $collection->getSelect()->having('total > 10');





              share|improve this answer


























                0












                0








                0







                Its a strange query you want to run, but this is how you do it:



                $collection = Mage::getModel('catalog/product')->getCollection();
                $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
                $collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
                $collection->getSelect()->having('total > 10');





                share|improve this answer













                Its a strange query you want to run, but this is how you do it:



                $collection = Mage::getModel('catalog/product')->getCollection();
                $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', null, 'left');
                $collection->getSelect()->columns(array('total' => new Zend_Db_Expr("at_qty.qty - e.entity_id")));
                $collection->getSelect()->having('total > 10');






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 14 '16 at 6:34









                Shawn AbramsonShawn Abramson

                2,4671815




                2,4671815

























                    0














                    Here is the example how to use Direct mysql in Magento



                    /**
                    * Get the resource model
                    */
                    $resource = Mage::getSingleton('core/resource');

                    /**
                    * Retrieve the write connection
                    */
                    $writeConnection = $resource->getConnection('core_write');

                    /**
                    * Retrieve our table name
                    */
                    $table = $resource->getTableName('catalog/product');

                    /**
                    * Set the product ID
                    */
                    $productId = 44;

                    /**
                    * Set the new SKU
                    * It is assumed that you are hard coding the new SKU in
                    * If the input is not dynamic, consider using the
                    * Varien_Db_Select object to insert data
                    */
                    $newSku = 'new-sku';

                    $query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
                    . (int)$productId;

                    /**
                    * Execute the query
                    */
                    $writeConnection->query($query);


                    For More see here.



                    Another way



                    $_products = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToSelect(array('name', 'product_url', 'small_image'))
                    ->addAttributeToFilter('sku', array('like' => 'UX%'))
                    ->load();


                    For more detail see here.






                    share|improve this answer
























                    • you didn't read my question i think

                      – Vipan Kumar Parjapati
                      May 13 '16 at 10:29











                    • I have read your question and these are just examples now what do you want ?

                      – Arunendra
                      May 13 '16 at 10:34
















                    0














                    Here is the example how to use Direct mysql in Magento



                    /**
                    * Get the resource model
                    */
                    $resource = Mage::getSingleton('core/resource');

                    /**
                    * Retrieve the write connection
                    */
                    $writeConnection = $resource->getConnection('core_write');

                    /**
                    * Retrieve our table name
                    */
                    $table = $resource->getTableName('catalog/product');

                    /**
                    * Set the product ID
                    */
                    $productId = 44;

                    /**
                    * Set the new SKU
                    * It is assumed that you are hard coding the new SKU in
                    * If the input is not dynamic, consider using the
                    * Varien_Db_Select object to insert data
                    */
                    $newSku = 'new-sku';

                    $query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
                    . (int)$productId;

                    /**
                    * Execute the query
                    */
                    $writeConnection->query($query);


                    For More see here.



                    Another way



                    $_products = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToSelect(array('name', 'product_url', 'small_image'))
                    ->addAttributeToFilter('sku', array('like' => 'UX%'))
                    ->load();


                    For more detail see here.






                    share|improve this answer
























                    • you didn't read my question i think

                      – Vipan Kumar Parjapati
                      May 13 '16 at 10:29











                    • I have read your question and these are just examples now what do you want ?

                      – Arunendra
                      May 13 '16 at 10:34














                    0












                    0








                    0







                    Here is the example how to use Direct mysql in Magento



                    /**
                    * Get the resource model
                    */
                    $resource = Mage::getSingleton('core/resource');

                    /**
                    * Retrieve the write connection
                    */
                    $writeConnection = $resource->getConnection('core_write');

                    /**
                    * Retrieve our table name
                    */
                    $table = $resource->getTableName('catalog/product');

                    /**
                    * Set the product ID
                    */
                    $productId = 44;

                    /**
                    * Set the new SKU
                    * It is assumed that you are hard coding the new SKU in
                    * If the input is not dynamic, consider using the
                    * Varien_Db_Select object to insert data
                    */
                    $newSku = 'new-sku';

                    $query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
                    . (int)$productId;

                    /**
                    * Execute the query
                    */
                    $writeConnection->query($query);


                    For More see here.



                    Another way



                    $_products = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToSelect(array('name', 'product_url', 'small_image'))
                    ->addAttributeToFilter('sku', array('like' => 'UX%'))
                    ->load();


                    For more detail see here.






                    share|improve this answer













                    Here is the example how to use Direct mysql in Magento



                    /**
                    * Get the resource model
                    */
                    $resource = Mage::getSingleton('core/resource');

                    /**
                    * Retrieve the write connection
                    */
                    $writeConnection = $resource->getConnection('core_write');

                    /**
                    * Retrieve our table name
                    */
                    $table = $resource->getTableName('catalog/product');

                    /**
                    * Set the product ID
                    */
                    $productId = 44;

                    /**
                    * Set the new SKU
                    * It is assumed that you are hard coding the new SKU in
                    * If the input is not dynamic, consider using the
                    * Varien_Db_Select object to insert data
                    */
                    $newSku = 'new-sku';

                    $query = "UPDATE {$table} SET sku = '{$sku}' WHERE entity_id = "
                    . (int)$productId;

                    /**
                    * Execute the query
                    */
                    $writeConnection->query($query);


                    For More see here.



                    Another way



                    $_products = Mage::getResourceModel('catalog/product_collection')
                    ->addAttributeToSelect(array('name', 'product_url', 'small_image'))
                    ->addAttributeToFilter('sku', array('like' => 'UX%'))
                    ->load();


                    For more detail see here.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 13 '16 at 10:12









                    ArunendraArunendra

                    6,13831642




                    6,13831642













                    • you didn't read my question i think

                      – Vipan Kumar Parjapati
                      May 13 '16 at 10:29











                    • I have read your question and these are just examples now what do you want ?

                      – Arunendra
                      May 13 '16 at 10:34



















                    • you didn't read my question i think

                      – Vipan Kumar Parjapati
                      May 13 '16 at 10:29











                    • I have read your question and these are just examples now what do you want ?

                      – Arunendra
                      May 13 '16 at 10:34

















                    you didn't read my question i think

                    – Vipan Kumar Parjapati
                    May 13 '16 at 10:29





                    you didn't read my question i think

                    – Vipan Kumar Parjapati
                    May 13 '16 at 10:29













                    I have read your question and these are just examples now what do you want ?

                    – Arunendra
                    May 13 '16 at 10:34





                    I have read your question and these are just examples now what do you want ?

                    – Arunendra
                    May 13 '16 at 10:34


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f115275%2fhow-to-use-expression-values-in-where-condition%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What other Star Trek series did the main TNG cast show up in?

                    Berlina muro

                    Berlina aerponto