【发布时间】:2012-09-15 23:52:01
【问题描述】:
我已经有这个查询:
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 是电话号码。
但现在我需要做的是:如果 dst 的第 5 个字符
有可能吗?
这样我得到了mysql语法错误:
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))
【问题讨论】: