如何在當前查詢上求和或添加(PDetail.DETAIL_FOR_QTY)?在sql查詢中求和aggerate
SELECT PDetail.PLU, PDetail.DETAIL_FOR_QTY, PLU.PLU_DESC, PLU.LAST_PRICE
FROM PDetail INNER JOIN
PLU ON PDetail.PLU = PLU.PLU_NUM
WHERE (PDetail.DEPT = 26) AND (PDetail.StoreNumber IN (1, 2, 3, 4, 7, 8, 10, 12, 14, 16)) AND (PDetail.TIME_STAMP BETWEEN CONVERT(DATETIME,
'2013-06-20 00:00:00', 102) AND CONVERT(DATETIME, '2013-06-20 23:59:59', 102))
ORDER BY PLU.PLU_DESC
目前,我得到的是這樣的:
08024401 1 item1 17.4900
08048003 1 item2 22.9900
08048004 1 item3 22.9900
08048004 1 item3 22.9900
我想加起來這兩個,因爲它們是相同的(基於PDetail INNER JOIN PLU ON PDetail.PLU = PLU。 PLU_NUM):
PDetail.PLU PDetail.DETAIL_FOR_QTY PLU.PLU_DESC Don't need to add this
08048004 1 item3 22.9900
08048004 1 item3 22.9900
期望的結果:
08024401 1 item1 17.4900
08048003 1 item2 22.9900
08048004 2 item3 22.9900
能否請您發表您的預期效果? –
請將它添加到您的答案,以便它被格式化。 –
因此,如果Item3在您的原始結果中設置了兩次不同的最後價格,那麼您需要兩行還是兩個價格的最大值? –