Can someone explain me why this works:
select val1, val2,
count(case when table2.someID in (1, 2, 3, 48967, 123456) then table2.someId end) as val3
from table1
join table2 on table1.someId = table2.someId
where blabla
group by val1, val2
order by val1
but this query here:
select val1, val2,
count(case when table2.someID in (Select someId from table567) then table2.someId end) as val3
from table1
join table2 on table1.someId = table2.someId
where blabla
group by val1, val2
order by val1
gives error:
Cannot perform an aggregate function on an expression containing an
aggregate or a subquery.
(someId is PK in table2)
You can get around this by using a left join rather than a subquery.