訂單包含價格不同的同一產品。如何根據每個產品的單排產品獲得不同的價格
如何獲得每個產品的不同價格清單,每個產品一行?
我試圖
SELECT product, string_AGG(DISTINCT price::text, ',' ORDER BY price)
FROM (VALUES ('A', 100), ('A', 200) , ('B', 200))
orderdetail (product, price)
GROUP BY product
,但得到的錯誤
ERROR: in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
LINE 1: ...ct, string_AGG(DISTINCT price::text, ',' ORDER BY price DESC...
如何解決這一問題?
使用Postgres 9.4。
這可能需要爲 How to find changed prices in last two purchase invoices
價格在表中的OrderDetail第二列::文本投公司變更類型爲文本得到的字符串價目表的Postgres。它可以寫成標準sql – Andrus
中的'cast(price as text)'當你說'如何獲得每個產品的不同價格清單?'時,你的意思是每個產品單行嗎? –
是的,每個產品的單行包含不同價格列表的升序。第二列可能也是數組而不是字符串 – Andrus