select
case when type = A and cnt = 0 and date > current_date - 15 then 1
case when type = A and cnt > 0 and cnt< 5 and date > current_date - 15 - cnt * 30 then 1
...
else 0
end as flag
from table
where flag = 1
;
case when then .. else end
存储过程做不是很简单吗