如題,訂單表order(phone),訂單商品表detail(order_id,goods_id,price_sell,amount),
現在要根據order表的一些欄位和detail表里的欄位查詢訂單資訊,
如果只根據detail表里的goods_id查詢那么DISTINCT 可以實作。
現在的問題是,我要現實goods_id=1的小計金額(amount*price_sell)也顯示出來,
搞了好久不會,
uj5u.com熱心網友回復:
最簡單的辦法,寫兩個SELECT,一個詳細的,一個小計的,然后UNION ALL在一起。uj5u.com熱心網友回復:
可否舉個例子
uj5u.com熱心網友回復:
分組合計 然后把結果作為新表 通過表關聯可實作uj5u.com熱心網友回復:
大哥,直接幫我寫一下唄
uj5u.com熱心網友回復:
select* from a,b,(select goods_id,sum(amount)*price_sell from b group ) c where a.*=b.*,b.goodsid=c.goodsiduj5u.com熱心網友回復:
你這不行啊,報錯
uj5u.com熱心網友回復:
我簡寫的
,提供一個思路而已。
SELECT
a.*, b.*, c.prices
FROM ORDER a, detail b,
(
SELECT goods_id, sum(amount) * price_sell AS prices
FROM
detail GROUP
) c
WHERE a.id = b.order_id and b.goods_id = c.goods_id
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/45075.html
標籤:MySQL
上一篇:求sql大神
