0
好了,我們有很多的銷售數據爲每一位客戶。我已經可以輕鬆找到所需的查詢使用簡單的查詢,以獲得銷售爲每個銷售代表的總容積:結合的MySQL查詢產量不正確的答案
SELECT `MerchantAddresses`.`Rep Number` AS `Rep Number`,
SUM(`RESIDUALS_2010_12`.`Qual Cr Vol` + `RESIDUALS_2010_12`.`Qual Ch Vol`) AS `VOL_2010_12`,
`Reps`.`First` AS `First`,
`Reps`.`Last` AS `Last`
FROM `MerchantAddresses`, `RESIDUALS_2010_12`, `Reps`
WHERE `RESIDUALS_2010_12`.`MID` = `MerchantAddresses`.`MID` AND
`Reps`.`ID` = `MerchantAddresses`.`Rep Number`
GROUP BY `MerchantAddresses`.`Rep Number`
ORDER BY SUM(`RESIDUALS_2010_12`.`Qual Cr Vol` + `RESIDUALS_2010_12`.`Qual Ch Vol`) DESC
此代碼工作完全正常,返回一個分組表中的銷售代表的銷售總額爲單月。目前,我們已經進行了三次不同的查詢以獲得3個月的銷售數據。我想將這三個查詢合併爲一個。
所以,我做了以下內容:
SELECT `MerchantAddresses`.`Rep Number` AS `Rep Number`,
SUM(`RESIDUALS_2010_12`.`Qual Cr Vol` + `RESIDUALS_2010_12`.`Qual Ch Vol`) AS `VOL_2010_12`,
SUM(`RESIDUALS_2010_11`.`Qual Cr Vol` + `RESIDUALS_2010_11`.`Qual Ch Vol`) AS `VOL_2010_11`,
SUM(`RESIDUALS_2010_10`.`Qual Cr Vol` + `RESIDUALS_2010_10`.`Qual Ch Vol`) AS `VOL_2010_10`,
`Reps`.`First` AS `First`,
`Reps`.`Last` AS `Last`
FROM `MerchantAddresses`, `RESIDUALS_2010_12` JOIN ON `RESIDUALS_2010_11` JOIN ON `RESIDUALS_2010_10`, `Reps`
WHERE `RESIDUALS_2010_12`.`MID` = `MerchantAddresses`.`MID` AND
`RESIDUALS_2010_11`.`MID` = `MerchantAddresses`.`MID` AND
`RESIDUALS_2010_10`.`MID` = `MerchantAddresses`.`MID` AND
`Reps`.`ID` = `MerchantAddresses`.`Rep Number`
GROUP BY `MerchantAddresses`.`Rep Number`
ORDER BY SUM(`RESIDUALS_2010_12`.`Qual Cr Vol` + `RESIDUALS_2010_12`.`Qual Ch Vol`) DESC
我發現的是,我居然與此查詢得到不正確的值。它的工作原理,但成交量值我獲得每個銷售代表的其實是太小了......
任何想法?謝謝!
你是輝煌的我的朋友。 – altexpape 2011-02-10 00:01:18