SQL - 总和聚合函数

我对 SQL 还很陌生,所以请记住这一点。

我有一个包含数据的表格,该表格分为两个中心“多伦多和蒙特利尔”,共有 78 行(每个中心 39 行),有多个列。我想获得特定日期范围(月)的每个中心的 X 列的全国总数(总和)。例如,2018 年 1 月蒙特利尔 + 多伦多中心之间的全职员工总数。例如,逻辑语句是将多伦多 + 蒙特利尔 2018 年 1 月的结果相加,得出全国总数。尽管以我的初学者技能,我在编写可以执行而没有语法错误的 sql 查询时遇到了麻烦。

select sum(fte), daterange, center
from (
select  'Toronto' as Center,
        sum(fte) as total fte
from dbo.example
where daterange = '2015-11-01'
group by total fte

union 

select  'Montreal' as Center,
        sum(fte) as total fte
from dbo.example
where daterange = '2015-11-01'
group by total fte
)temptable
group by total fte

上面的查询给了我一个错误“'fte' 附近的语法不正确。” fte 是我表中的一列。

请告诉我我做错了什么。

干杯!

杰米·德克

查询应如下所示:

select Center,
  sum(fte) as "[total fte]"
from dbo.example
where daterange = '2015-11-01'
  and Center in ('Toronto','Montreal')
group by Center

了解在属性中心存在这些字符串。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章