Home > Backend Development > PHP Tutorial > sql语句转换成Laravel ORM的问题。

sql语句转换成Laravel ORM的问题。

WBOY
Release: 2016-06-06 20:20:20
Original
1281 people have browsed it

<code>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_count
FROM
    (
        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 e
GROUP BY e.stock_code, e.trade_type</code>
Copy after login
Copy after login

这段sql转换成ORM应该怎么写啊= =。
Laravel用的不多,求高玩赐教。。

踩我的朋友们,嫌我问的问题low?问的low你来答啊。答不出来还踩,什么心态。?

回复内容:

<code>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_count
FROM
    (
        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 e
GROUP BY e.stock_code, e.trade_type</code>
Copy after login
Copy after login

这段sql转换成ORM应该怎么写啊= =。
Laravel用的不多,求高玩赐教。。

踩我的朋友们,嫌我问的问题low?问的low你来答啊。答不出来还踩,什么心态。?

转换成ORM增加了复杂性,降低了sql语句可读性,还不如直接用DB::select()来执行sql。

复杂的sql没必要改成orm

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template