mysql sum无法正常工作

时间:2015-03-19 14:23:22

标签: mysql

这是我的选择查询我试图从moldmaster获取moldNo如果有多个相同designMasterId的记录比它自动总和那个moldno但问题是当我试图获取moldNo而不是结果显示我double moldno

例子:4 + 3答案是14

SELECT designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,SUM(moldNo) AS moldNo
                                 ,mold,status
                     FROM   designMaster
                    JOIN item ON item.itemId = designMaster.itemId
                    JOIN process ON process.designMasterId = designMaster.designMasterId
                    JOIN moldmaster ON moldmaster.designMasterId = designMaster.designMasterId
                    GROUP BY designMaster.designMasterId
                    ORDER BY designMaster.designMasterId

2 个答案:

答案 0 :(得分:0)

试试这个: -

SELECT designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,SUM(moldNo) AS moldNo
                             ,mold,status
                FROM   designMaster
                JOIN item ON item.itemId = designMaster.itemId
                JOIN process ON process.designMasterId = designMaster.designMasterId
                JOIN moldmaster ON moldmaster.designMasterId = designMaster.designMasterId
                GROUP BY designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,mold,status
                ORDER BY designMaster.designMasterId

答案 1 :(得分:0)

这是我的选择查询,认为我得到了超出输出。

SELECT designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,SUM(moldNo) AS moldNo
                                 ,mold,status,processNm
                     FROM   designMaster,item,moldmaster,processmaster,process
                     WHERE  item.itemId = designMaster.itemId
                     AND   process.designMasterId = designMaster.designMasterId
                     AND  moldmaster.designMasterId = designMaster.designMasterId
                     AND  processmaster.processMasterId = designMaster.nextProcess
                    GROUP BY designMaster.designMasterId
                    ORDER BY designMaster.designMasterId