let’s imagine here is my report:
x
select 1 from dual
union all
select 2 from dual
union all
select 3 from dual
union all
select 4 from dual
Output:
1
2
3
4
If e.g. i want to hide part of the report in an easy way I simply add 1 = 2 to where clause:
select 1 from dual
union all
select 2 from dual
union all
select 3 from dual where 1 = 2
union all
select 4 from dual
Output:
1
2
4
Cool! However, when select uses aggregate functions, this trick does not help. The row is generated anyway:
select 1 from dual
union all
select 2 from dual
union all
select max(3) from dual where 1 = 2
union all
select 4 from dual
Output:
1
2
(null)
4
Someone maybe know a simple, easy way to hide such rows?
Advertisement
Answer
An aggregation query with no group by
always returns exactly one row — even if no rows are being aggregated.
You want to filter after the aggregation, so use having
:
select max(3) from dual having 1 = 2