我在员工工资的Postgres中有一张表(表名为“Emp_Play”)。表结构如下
Emp ID | PayDate | Amount |
0001 | 01/15/15 | 1450.00 |
0001 | 02/15/15 | 1455.00 |
0001 | 03/15/15 | 2100.00 |
0001 | 04/15/15 | 1450.00 |
每个员工都有这样的记录,三月是“奖金”月份。
我正在尝试编写一个有效的查询来平均员工的工资额,但要排除“奖金”月的日期。到目前为止,我想出了:
select avg("Amount") as AVG
from "Empl_Play"
where "PayDate" between '01/01/2015' and '01/31/2015' and "PayDate" between '03/01/2015' and '12/31/2015';
是否有更简单的方法来处理查询,以便排除“PayDate”中的某些条件,例如3月的“奖金月”?
答案 0 :(得分:0)
这样做你想要的吗?
select avg(Amount) as AVG
from Empl_Play
where extract(month from PayDate) <> 3 and
extract(year from PayDate) = 2015;