我正在尝试每月获取数据,为此,我创建了查询但有一些重复记录。这是我在sqlserver中的查询
SELECT DM.deptdesc,
PIM.itemcode,
PIM.itemdesc,
Isnull(Sum(IM.issuedqty), 0) AS 'Issued',
Datename(month, IM.dt) AS MONTH,
Year(IM.dt) AS year
FROM poitemmaster AS PIM
inner JOIN issuematerial AS IM
ON PIM.itemcode = IM.itemcode
LEFT OUTER JOIN departmentmaster AS DM
ON PIM.deptcode = DM.deptcode
WHERE PIM.itemcode = 'ICMEL00001'
GROUP BY DM.deptdesc,
PIM.itemcode,
PIM.itemdesc,
IM.issuedqty,
Datename(month, IM.dt),
Year(IM.dt)
我想要按月计算数量。我该怎么办?任何人有任何想法。?
从组中删除issuedqty列,并将SUM()添加到列列表中的同一列中
SELECT DM.deptdesc,
PIM.itemcode,
PIM.itemdesc,
Sum(ISNULL(IM.issuedqty, 0) AS 'Issued',
Datename(month, IM.dt) AS MONTH,
Year(IM.dt) AS year
FROM poitemmaster AS PIM
inner JOIN issuematerial AS IM
ON PIM.itemcode = IM.itemcode
LEFT OUTER JOIN departmentmaster AS DM
ON PIM.deptcode = DM.deptcode
WHERE PIM.itemcode = 'ICMEL00001'
GROUP BY DM.deptdesc,
PIM.itemcode,
PIM.itemdesc,
Datename(month, IM.dt),
Year(IM.dt)