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 adict
which looks like{'sk': u'S0013', 'cnt': Decimal('1971')}
socnt
in result is thekey
of thedict
instead ofvalue
..