Forum

Posted by Yuanyuan, Feb. 25, 2022, 12:58 p.m.

#14 Why my code is wrong

with amt as (select count(rental_id)as num, date(rental_ts)as dt
from rental
where extract(month from rental_ts) = '5'
group by dt)
SELECT sum(case when num > 100 then 1 else 0 end) as good_days,
sum(case when num <= 100 then 1 else 0 end) as bad_days
from amt
The bad days turn out to 1, but why? I assume it will be 25

Answers

Hey Yuanyuan,
That's the tricky part, please see my previous answer here:
https://sqlpad.io/forum/question/39/14-why-my-subquery-returns-only-7-results/
Cheers,
Leon
SQLPad user avatar

Leon (949)

Feb. 25, 2022, 4:49 p.m.