版主,
Select cpbhao,ssbumen, caozhuorq,月数,Sum(dangricl) as 总加工数量,Sum(posuns) as 破损数 from (Select cpbhao,ssbumen, Format(caozhuorq,'YYYYMM') as 月数,dangric,posuns from scrb) Group By ssbumen,月数
我改成了
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' 附近有语法错误
我将你给那句拆成了下面2句话,结果还都能成功查询,不报错。。。。
Select cpbhao,ssbumen, caozhuorq, Sum(dangricl) as 总加工数量,Sum(posuns) as 总破损数 from scrb Group By cpbhao,ssbumen, caozhuorq
Select cpbhao,ssbumen,Month(caozhuorq) as 月数,dangricl,posuns from scrb
我SQL语法基础差,能指教一下吗?我是SQL2005+WIN7环境
目前就是用了你这句。。。。
Select ssbumen, caozhuorq, Sum(dangricl) as 总加工数量,Sum(posuns) as 总破损数 from (Select cpbhao,ssbumen,Month(caozhuorq) as 月数,dangricl,posuns from scrb) Group By ssbumen, caozhuorq 我直接在SQL中执行报错的。。。
Select t.ssbumen, t.月数, Sum(dangricl) as 总加工数量,Sum(posuns) as 总破损数 from (Select cpbhao,ssbumen,Month(caozhuorq) as 月数,dangricl,posuns from scrb) as t Group By ssbumen, 月数 就正确
Select cpbhao,t.ssbumen,ygsn,周数,Sum(dangricl) as 总加工数量,Sum(posuns) as 破损数from (Select cpbhao,t.ssbumen,ygsn,Cstr(Year(caozhuorq))+'WK'+Cstr(DatePart('ww',caozhuorq)) as 周数,dangricl,posunsfrom scrb) as tGroup By cpbhao,ssbumen,周数,ygsn