sql - subquery select when group by is null -
i've got query cannot figure out.
select ( select count(bar.id) bar foo.some_id = bar.some_id ) num_bar foo group some_id
if foo looks this:
id|some_id ---------- 1 |null 2 |apple 3 |orange
and bar looks this
id|some_id ---------- 1 |null 2 |apple 3 |orange 4 |null 5 |apple 6 |orange
i expect return:
num_bar ------- 2 2 2
howerver, count on null grouping returns 0 each time.
what proper way account clause when group null?
sql aggregate functions , comparisons may ignore null values in computation
what might want give value , interpret nulls accordingly. in below query, asking query interpret null values -1.
select ( select count(bar.id) bar isnull(foo.some_id, -1) = isnull(bar.some_id,-1) ) num_bar foo group isnull(some_id,-1)
Comments
Post a Comment