The problem of converting SQL statements into Laravel ORM.

Source: Internet
Author: User
SELECT    e.external_account_id,    e.trade_type,  e.stock_code,    e.name,    e.stock_name,    SUM(e.trade_price * e.trade_count) / SUM(e.trade_count) AS trade_price,    SUM(e.trade_count) AS trade_countFROM    (        SELECT            a.id,            a.external_account_id,            a.internal_account_id,            a.trade_price,            a.trade_count,            b.stock_code,            b.trade_type,            c.name as stock_name,            d.name        FROM            trades a,            orders b,            stocks c,            external_accounts d        WHERE            a.order_id = b.id        AND b.stock_code = c.code        AND a.external_account_id = 29        AND d.id = 29    ) AS eGROUP BY e.stock_code, e.trade_type

This SQL conversion to ORM should be how to write ah = =.
Laravel use not much, ask high play enlighten.

Step on my friends, I ask the question of low? Ask the low you come to answer AH. Do not come out also tread, what mentality.?

Reply content:

SELECT    e.external_account_id,    e.trade_type,  e.stock_code,    e.name,    e.stock_name,    SUM(e.trade_price * e.trade_count) / SUM(e.trade_count) AS trade_price,    SUM(e.trade_count) AS trade_countFROM    (        SELECT            a.id,            a.external_account_id,            a.internal_account_id,            a.trade_price,            a.trade_count,            b.stock_code,            b.trade_type,            c.name as stock_name,            d.name        FROM            trades a,            orders b,            stocks c,            external_accounts d        WHERE            a.order_id = b.id        AND b.stock_code = c.code        AND a.external_account_id = 29        AND d.id = 29    ) AS eGROUP BY e.stock_code, e.trade_type

This SQL conversion to ORM should be how to write ah = =.
Laravel use not much, ask high play enlighten.

Step on my friends, I ask the question of low? Ask the low you come to answer AH. Do not come out also tread, what mentality.?

Converting to ORM adds complexity and reduces the readability of SQL statements, rather than directly DB::select() executing SQL.

Complex SQL doesn't need to be an ORM.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.