クエリは特定の数値を返します。クエリは次のとおりです。
select
count(distinct case when (A or B or C) and D then table_a.field1 else null end)
from table_a
left join table_b on table_b.x = table_a.y
group by table_a.y
;
ここで、A、B、C、および D には条件が与えられます。今、この形式で書かれています:
select
sum((select count(1) from table_b where table_b.x = table_a.y and ((A or B or C) and D) ))
from table_a
left join table_b on table_b.x = table_a.y
group by table_a.y
;
結果は、count(distinct) で得たものと一致しません。
サブクエリで count(distinct) を記述する正しい方法は何ですか?