sql - is there a way to check if a value is zero and do this or do that in mysql -
i want sql query
select * members m abs(due/30*service_charge)>='0' , abs(due/30*service_charge)<='200' group id
but in cases value of service_charge 0 , want write if service_charge = 0 , service_charge = 1;
is there way ?.
use case
:
select * members m abs(due/30*(case when service_charge = 0 1 else service_charge end) >= 0 , abs(due/30*(case when service_charge = 0 1 else service_charge end)<= 200 group id;
however, typically handled using nullif()
-- meaning null
returned calculation:
select * members m abs(due / 30 * nullif(service_charge, 0) >= 0 , abs(due / 30 * nullif(service_charge, 0) <= 200 group id;
also, don't use single quotes around numeric constants. confuses people , confuse sql optimizer.
Comments
Post a Comment