这是我收到的错误:在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
我在
编程时SELECT prod.LineNumber ,
"Pounds Made" = SUM(prod.PoundsMade) ,
"Down Time" = SUM(prodDown.DownTimeHrs + DownTimeMins / 60) ,
prodDown.LineNumber ,
availHrs.LineNumber ,
"Available Hours" = SUM(availHrs.AvailableHRS)
FROM rpt_Line_Shift_Prod AS prod
INNER JOIN rpt_Line_Shift_ProdDownTime AS prodDown
INNER JOIN rpt_LINE_Shift_AvailableHrs AS availHrs ON prodDown.LineNumber = availHrs.LineNumber ON prodDown.LineNumber = prod.LineNumber
--ON availHrs.LineNumber = prod.LineNumber
GROUP BY prod.LineNumber
我在这里使用了三个表,所有我已经重命名为prodDown,prod和availHrs。
谢谢!
答案 0 :(得分:2)
SELECT prod.LineNumber
,"Pounds Made" = SUM(prod.PoundsMade)
,"Down Time" = SUM(prodDown.DownTimeHrs + DownTimeMins/60)
, prodDown.LineNumber
, availHrs.LineNumber
,"Available Hours" = SUM(availHrs.AvailableHRS)
FROM rpt_Line_Shift_Prod AS prod
INNER JOIN rpt_Line_Shift_ProdDownTime AS prodDown
ON prodDown.LineNumber = prod.LineNumber
INNER JOIN rpt_LINE_Shift_AvailableHrs AS availHrs
ON prodDown.LineNumber = availHrs.LineNumber
GROUP BY prod.LineNumber,prodDown.LineNumber, availHrs.LineNumber
答案 1 :(得分:0)
将prodDown.LineNumber``and
availHrs.LineNumber`放入GROUP BY子句中:
GROUP BY prod.LineNumber,prodDown.LineNumber, availHrs.LineNumber
选择列表中没有像sum
这样的聚合的所有列都必须在GROUP BY
子句中。
答案 2 :(得分:0)
您只能按prod.LineNumber
分组
而在你的选择中你也有
prodDown.LineNumber, availHrs.LineNumber
将它们添加到组子句
GROUP by prod.LineNumber,prodDown.LineNumber, availHrs.LineNumber
答案 3 :(得分:0)
在列上使用SUM()
或任何其他aggregate function时,您需要确保选择列表中的任何其他列也已分组。这将确保您不会得到任何重复。因此,正如其他答案所示,您需要确保在GROUP BY
子句中包含其他列。