如何附加“;十进制;从Python中的MySQL查询结果

如何附加“;十进制;从Python中的MySQL查询结果,python,mysql,sql,pymysql,Python,Mysql,Sql,Pymysql,我使用以下代码在Python中运行MySql查询: cur = conn.cursor() query = ("""select sum(if(grade is not null,1,0)) as `test`, sum(if(grade < 7,1,0)) as `bad`, sum(if(grade < 7,1,0))/sum(if(grade is not null,1,0))*100 as `Pct Bad Grade`, student fr

我使用以下代码在Python中运行MySql查询:

cur = conn.cursor()
query = ("""select sum(if(grade is not null,1,0)) as `test`,
    sum(if(grade < 7,1,0)) as `bad`,
    sum(if(grade < 7,1,0))/sum(if(grade is not null,1,0))*100 as `Pct Bad Grade`,
    student
    from grades_database
    where test_date >= '2014-08-01'
    group by student
    order by `Pct Bad Grade` desc;""")
cur.execute(query)
我需要删除值前面的“Decimal”字符串

我试着使用下面的

但它给了我这个

[20.0, 5.0, 3.0, 7.0, 7.0, 2.0, 6.0, 7.0, 7.0, 7.0,...]
理想情况下,我希望重新排列输出的顺序,并得到如下结果

(Decimal('1'), Decimal('3'), Decimal('50.0000'), 'John Doe')
(John Doe, 50, 3, 1)]


更改查询的顺序以获得所需的顺序(名称然后等级)


Decimal
对象比
float
对象更精确。当您打印或写入数据时,您只会得到数值,例如:
print Decimal('50.0000')
给出:
50.0000
(John Doe, 50, 3, 1)]
(Decimal('1'), Decimal('3'), Decimal('50.0000'), 'John Doe')
cur = conn.cursor()
query = ("""select student,
    sum(if(grade is not null,1,0)) as `test`,
    sum(if(grade < 7,1,0)) as `bad`,
    sum(if(grade < 7,1,0))/sum(if(grade is not null,1,0))*100 as `Pct Bad Grade`
    from grades_database
    where test_date >= '2014-08-01'
    group by student
    order by `Pct Bad Grade` desc;""")
cur.execute(query)
for index, row in enumerate(cur):
    if index:
        output[index] = int(row)
print output