Here is my SQL:
SELECT * FROM (SELECT sk, SUM(qty) AS cnt FROM order WHERE sk LIKE '%s%s' AND days <= '%s' GROUP BY sk ORDER by cnt DESC) AS tmp WHERE tmp.cnt >3;
and here is my code:
result = cur.fetchall()
for sk, cnt in result:
rat = cnt/total
then I get a error:
TypeError: unsupported operand type(s) for /: 'str' and 'Decimal'
I have no idea why cnt is type str instead of int.
Here is the problem: each row of the
fetchall()is adictwhich looks like{'sk': u'S0013', 'cnt': Decimal('1971')}socntin result is thekeyof thedictinstead ofvalue..