我有這樣的結果,從我的查詢設置:的MySQL結果集組合列
OrderId CustomerId ProducerId CustomerPayment ProducerPayment
1 1 3 10 5
1 1 4 10 5
1 2 3 10 5
1 2 4 10 5
我需要這個結果返回到這一點:
OrderId UserId Payment
1 1 20
1 2 20
1 3 10
1 4 10
只是結合CustomerId
和ProducerId
到UserId
。與Payment
列相同。
有什麼辦法可以通過簡單的使用select
和group by
來實現嗎?我在迴避temp tables
,呼籲多重queries
等優化。我希望這是可能的。
非常感謝
您將需要對數據進行規範化處理,以實現您要查找的內容。打破客戶,客戶支付作爲一個記錄,並將產品和生產者支付作爲另一個記錄 – ajreal
謝謝,但我怎麼能打破它們?第一個表格已經是查詢結果。只需要操縱它們。 – KaeL
你的第一個查詢是什麼? –