【发布时间】:2016-10-21 10:14:00
【问题描述】:
我的查询是
SELECT
CustBillPayment.CustomerId, CustBillPayment.Customer_Name,
CustBillPayment.CustBill_Total, CustBillPayment.CustBill_Paid,
CustBillPayment.CustBill_ReamingAmt, CustBillPayment.Created_Date,
CustBillPayment.Delivery_Date, CustBillPayment.Updated_Date,
Shirt_Mes.Shirt_Type, Shirt_Mes.Shirt_Qty, Shirt_Mes.Shirt_Price,
Shirt_Mes.Shirt_Total,
Pant_Mes.Pant_Type, Pant_Mes.Pant_QTY, Pant_Mes.Pant_Total,
Pant_Mes.Pant_Price
FROM
((CustBillPayment
INNER JOIN
Shirt_Mes ON CustBillPayment.CustomerId = Shirt_Mes.CustomerId)
INNER JOIN
Pant_Mes ON CustBillPayment.CustomerId = Pant_Mes.CustomerId)
WHERE
CustBillPayment.CustomerId = 17
输出是这样的并显示重复的行:
CustomerId CustNm SType SQty SPrice STotal PType PQTY PTotal PPrice
-------------------------------------------------------------------------------
17 lakhan sType1 2 200 400 PType3 3 900 300
17 lakhan sType1 2 200 400 PType4 1 400 400
17 lakhan sType2 1 250 250 PType3 3 900 300
17 lakhan sType2 1 250 250 PType4 1 400 400
但我想要
CustomerId CustNm SType SQty SPrice STotal PType PQTY PTotal PPrice
-------------------------------------------------------------------------------
17 lakhan sType1 2 200 400 PType3 3 900 300
17 lakhan sType2 1 250 250 PType4 1 400 400
【问题讨论】:
-
添加一个选择并按您想要的字段分组:select [yourfileds] from (your original query) group by [yourfields]
-
您是否尝试将
Select Distinct和Group By添加到此查询? SType 列似乎是分组的好列