sql求纠正
消息 1033,级别 15,状态 1,第 1 行
除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
消息 156,级别 15,状态 1,第 2 行
关键字 'as' 附近有语法错误。
select * from (
select distinct ISNULL(MONTHLYSUM.prod,' ') as prod, V_BSC.mergercode,V_BSC.mergername as mergername,V_MONTHLYCAN.系列 XL , round(ISNULL(sum((monthlysum.selsell+monthlysum.ensell)*MONTHLYSUM.[convert]),0),0) SELL from MONTHLYSUM,V_BSC,V_MONTHLYCAN where MONTHLYSUM.AREACODE = V_BSC.号码 and MONTHLYSUM.prod=V_MONTHLYCAN.品名 and monthlysum.ymonth>='201211'and monthlysum.ymonth<='201211' and V_MONTHLYCAN.系列 in ('22S-系列','75S-系列') group by V_BSC.mergercode,V_BSC.mergername,MONTHLYSUM.prod ,V_MONTHLYCAN.系列 order by V_BSC.mergercode,prod) as T1,
(select distinct ISNULL(V_MONTHLYCAN.是否生产,' ')as sfsc ,ISNULL(V_MONTHLYCAN.是否新品,' ') as sfxp,MONTHLYSUM.SELRANK as xsdj,monthlysum.prod as prod from monthlysum,V_MONTHLYCAN where monthlysum.prod=V_MONTHLYCAN.品名 and monthlysum.ymonth>='201211'and monthlysum.ymonth<='201211') as T2
where T1.prod = T2.prod
------最佳解决方案--------------------消息 1033,级别 15,状态 1,第 1 行
除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
消息 156,级别 15,状态 1,第 2 行
关键字 'as' 附近有语法错误。
AS附近错了
------其他解决方案--------------------select * from (
select distinct ISNULL(MONTHLYSUM.prod,' ') as prod, V_BSC.mergercode,V_BSC.mergername as mergername,V_MONTHLYCAN.系列 XL , round(ISNULL(sum((monthlysum.selsell+monthlysum.ensell)*MONTHLYSUM.[convert]),0),0) SELL from MONTHLYSUM,V_BSC,V_MONTHLYCAN where MONTHLYSUM.AREACODE = V_BSC.号码 and MONTHLYSUM.prod=V_MONTHLYCAN.品名 and monthlysum.ymonth>='201211'and monthlysum.ymonth<='201211' and V_MONTHLYCAN.系列 in ('22S-系列','75S-系列') group by V_BSC.mergercode,V_BSC.mergername,MONTHLYSUM.prod ,V_MONTHLYCAN.系列) as T1,
(select distinct ISNULL(V_MONTHLYCAN.是否生产,' ')as sfsc ,ISNULL(V_MONTHLYCAN.是否新品,' ') as sfxp,MONTHLYSUM.SELRANK as xsdj,monthlysum.prod as prod from monthlysum,V_MONTHLYCAN where monthlysum.prod=V_MONTHLYCAN.品名 and monthlysum.ymonth>='201211'and monthlysum.ymonth<='201211') as T2
where T1.prod = T2.prod