添加字段时的语法错误

时间:2017-10-17 20:23:14

标签: select ssms average

以下代码适用于平均

 select
 [state], areatype, area, '00' [period], indcode, ownership, 
 avg(sites) sites, avg(employment) employment
 from dbo.tablename
 group by [state], areatype, area, indcode, ownership;

我保持简短和简单,以便学习这个概念。我在第二行和第五行添加了两个字段,现在出现语法错误。提供任何见解?

 select
 [state], areatype, area, periodyear, '00' [period], indcodetype, indcode, ownership, 
 avg(sites) sites, avg(employment) employment
 from dbo.tablename
 group by [state], areatype, area, periodyear, incodetype, indcode, ownership;

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'sites'.

1 个答案:

答案 0 :(得分:0)

由于我无法解释的原因,我一次添加一个元素并且它正在工作。如果我输入全部,我会得到语法错误,但如果我开始使用的是什么,一次添加一个项目并执行,它就可以了。