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
這段sql轉換成ORM應該怎麼寫啊= =。
Laravel用的不多,求高玩賜教。。
踩我的朋友們,嫌我問的問題low?問的low你來答啊。答不出來還踩,什麼心態。?
回複內容:
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
這段sql轉換成ORM應該怎麼寫啊= =。
Laravel用的不多,求高玩賜教。。
踩我的朋友們,嫌我問的問題low?問的low你來答啊。答不出來還踩,什麼心態。?
轉換成ORM增加了複雜性,降低了sql語句可讀性,還不如直接用DB::select()
來執行sql。
複雜的sql沒必要改成orm