I already have this query:
cursor.execute("SELECT calldate, dst, billsec, accountcode, disposition,
(billsec/60*%s) as total
FROM cdr
WHERE calldate >= '%s' and calldate < '%s'
and disposition like '%s' and accountcode = '%s'
and dst like '%s'" %(rate, start_date, end_date, status, accountcode, destino)
)
Obs: dst is a telephone number.
But now what I need to do is: If the 5th char of dst is <= 5, then billsec/60*0.11 as total else billsec/60*0.16.
Is it possible?
This way I got an error in mysql syntax:
cursor.execute("""SELECT calldate, dst, billsec, accountcode, disposition,
case when cast(substring(dst,4,1), unsigned) <= 5 then
billsec/60*%s as total
else
billsec/60*%s as total
end case
FROM cdr where calldate >= '%s' and calldate < '%s' and disposition like '%s' and accountcode = '%s' and dst like '%s'""" %(rate_fixo, rate_movel, start_date, end_date, status, accountcode, destino))