示例表
Cust_no | Item_no | Discount_Amt |Discount_%|
A123 | ITEM123 | 0.1 | |
AB321 | ITEM123 | 50 | |
A123 | ITEM123 | | 3 |
CD343 | ITEM345 | | 2 |
和我想要的结果:
Cust_no | Item_no | Discount Amt| Discount_%|
A123 | ITEM123 | 0.1 | 3 |
AB321 | ITEM123 | 50 | 0 |
CD343 | ITEM345 | | 2 |
如何在SQL中获得该结果?
答案 0 :(得分:0)
试试这个:
SELECT Cust_no,Item_no,SUM(Discount_Amt),SUM(Discount_%)
FROM TableName
GROUP BY Cust_no,Item_no
答案 1 :(得分:0)
我认为你正在寻找与此类似的东西
SELECT Cust_no,Item_no, MAX(Discount_Amt),MAX(Discount_%)
FROM Table
GROUP BY Cust_no, Item_no