| Server IP : 162.241.219.206 / Your IP : 216.73.216.195 Web Server : Apache System : Linux box5669.bluehost.com 5.14.0-687.15.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 11 08:51:45 EDT 2026 x86_64 User : signavd5 ( 2863) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/firebird/sql.extensions/ |
Upload File : |
# FILTER clause for aggregate functions
The `FILTER` clause for aggregate function is a shortcut for when an aggregate function is used with some condition (decode, case, iif) to disconsider some values in the aggregation.
The clause could be used with all aggregate functions in aggregate or windowed (`OVER`) calls, but cannot be used with window-only functions like `DENSE_RANK`.
For example, if in the same query there is a need to count the number of status = 'A' and the number of status = 'E' as different columns, the old way to do it is:
```sql
select count(decode(status, 'A', 1)) status_a,
count(decode(status, 'E', 1)) status_e
from data;
```
With `FILTER` that conditions could be more explicit:
```sql
select count(*) filter (where status = 'A') status_a,
count(*) filter (where status = 'E') status_e
from data;
```
## Syntax
```
aggregate_function [FILTER (WHERE <condition>)] [OVER (<window>)]
```