Select cpbhao,ssbumen, caozhuorq,月数,Sum(dangricl) as 总加工数量,Sum(posuns) as 破损数 from (Select cpbhao,ssbumen, month(caozhuorq) as 月数,dangric,posuns from scrb) Group By ssbumen,月数
报错 关键字 'Group' 附近有语法错误 我没有少什么列名?我错在哪里?
我用下面语句:
Select cpbhao,ssbumen, caozhuorq,Sum(dangricl) as 总加工数量,Sum(posuns) as 总破损数 ,sum( leijs), gongxubianhao,sum( zxljs) from scrb Group By cpbhao,ssbumen,caozhuorq,leijs, gongxubianhao,zxljs order by cpbhao,ssbumen,caozhuorq
竞然能查出了2条 gongxubianhao 列(是一个字符型)的值不同,而其他的列都是相同的,我不是用了按日期分组吗?
高手能给个指点一下吗?
------解决方案--------------------
SELECT
cpbhao, ssbumen, caozhuorq, 月数, SUM(dangricl) AS 总加工数量, SUM(posuns) AS 破损数
FROM
(SELECT
cpbhao ,
ssbumen ,
MONTH(caozhuorq) AS 月数 ,
dangric ,
posuns
FROM
scrb) AS t --这里加一别名
GROUP BY
ssbumen, 月数