【发布时间】:2014-09-28 18:52:47
【问题描述】:
我有一张桌子,看起来像是在闲置。
DepartmentId | Salary | Status
----------------------------------
1 | 5 | active
1 | 10 | active
1 | 15 | passive
1 | 20 | passive
我想选择这个带有闲置输出的表。
Columns:
DepartmentId,
Sum of salary where status is active ,
Sum of salary where status is passive.
DepartmentId | Sum(salary) where status is active | Sum(salary) where status is passive
-------------------------------------------------------------------------------------------
1 | 15 | 35
我使用 postgresql 作为数据库。 我如何查询表以获取输出为上? 谢谢。
【问题讨论】:
标签: sql postgresql group-by aggregate-functions window-functions