消息8120,级别16,状态1,行5列在选择列表中无效,因为它未包含错误

时间:2018-05-09 23:12:06

标签: sql-server tsql group-by ssms union-all

  

Msg 8120,Level 16,State 1,Line 5   列在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。

这似乎是一个常见的错误,但我查找的每个结果都有一个group by子句或语句。我的例子没有。以下是使用的代码。有关如何解决此错误的任何想法?

 select year, qtr, area, industry, ownership, employment
 from indstry
 where ( area = '32001' or area = '32005' or area = '32007' or area = 
 '32009' or area = '32011' or area = '32013' or area ='32015' or area = 
 '32017' or area = '32019' or area = '32021' or area = '32023' or area = 
 '32027' or area = '32033' ) and year ='2016'
 union all
 select year, NULL as qtr, '99999' as Area, NULL as industry, NULL as 
 ownership, sum (employment) as employment
 From industry
 where ( area = '32001' or area = '32005' or area = '32007' or area = 
 '32009' or area = '32011' or area = '32013' or area ='32015' or area = 
 '32017' or area = '32019' or area = '32021' or area = '32023' or area = 
 '32027' or area = '32033' ) and year ='2016'

0 个答案:

没有答案