Reputation: 51
I have created this query, but sometimes this part (CEILING(TIMESTAMPDIFF(MONTH, od.insstart, NOW()) / od.term)
returns 0, So I want to check result from this part and if it's equal to 0, to change it to 1, before compare it with second part = (SELECT COUNT(id)
is there a way to do this ?
SELECT id FROM od where pol = '123' AND (CEILING(TIMESTAMPDIFF(MONTH, od.insstart, NOW()) / od.term) = (SELECT COUNT(id) FROM od as tt WHERE tt.policyNumber = '123'))
If result from (CEILING(TIMESTAMPDIFF(MONTH, od.insstart, NOW()) / od.term)
is equal to 0 -> change it to 1 and then compare with second part which is (SELECT COUNT(id)
Upvotes: 0
Views: 44
Reputation: 42728
GREATEST( CEILING(TIMESTAMPDIFF(MONTH, od.insstart, NOW()) / od.term), 1 )
Upvotes: 1