只是尝试按两列分组选定的记录
SELECT FSB_ProcessItems.InvId,
FSB_ProcessItems.ItemId,
FSB_Processes.Code,
Sum(FSB_ProcessItems.Qty),
FSB_Processes.Date
FROM FSB_ProcessItems
INNER JOIN FSB_ProcessStudents ON FSB_ProcessItems.ProStudentId = FSB_ProcessStudents.ProStudentId
INNER JOIN FSB_Processes ON FSB_Processes.ProcessId = FSB_ProcessStudents.ProcessId
GROUP BY FSB_ProcessItems.InvId, FSB_ProcessItems.ItemId
我有错误:
专栏''在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
FSB_Processes.Code
和FSB_Processes.Date
在尝试分组之前,正确选择了记录,所以我只是遇到分组问题
搜索解决方案,但由于我不能完全理解问题,因此没有太多运气
所以我正在寻找解释和解决方案。
答案 0 :(得分:1)
您必须在group by子句中放入没有聚合函数的所有选定列
SELECT FSB_ProcessItems.InvId,
FSB_ProcessItems.ItemId,
FSB_Processes.Code,
Sum(FSB_ProcessItems.Qty),
FSB_Processes.Date
FROM FSB_ProcessItems
INNER JOIN FSB_ProcessStudents ON FSB_ProcessItems.ProStudentId = FSB_ProcessStudents.ProStudentId
INNER JOIN FSB_Processes ON FSB_Processes.ProcessId = FSB_ProcessStudents.ProcessId
GROUP BY FSB_ProcessItems.InvId, FSB_ProcessItems.ItemId, FSB_Processes.Date, FSB_Processes.Code
答案 1 :(得分:1)
你需要决定你想要什么。如上所述,您应该从Date
中取出SELECT
和SELECT pi.InvId, pi.ItemId, Sum(pi.Qty)
-- p.Code, p.Date
FROM FSB_ProcessItems pi INNER JOIN
FSB_ProcessStudents s
ON pi.ProStudentId = s.ProStudentId INNER JOIN
FSB_Processes p
ON p.ProcessId = s.ProcessId
GROUP BY pi.InvId, pi.ItemId;
:
GROUP BY
如果您想为代码和/或日期分别添加一行,请将margin_Top
包含在内。