我不断收到错误消息,提示我的值未位于有效记录中。我已经在 MySQL 中成功执行了查询,但我认为我忽略了代码中的某些内容。
query = QtSql.QSqlQuery("select patient_id," +
"(SUM(IF(uom_id = 1, value, 0)) / SUM(IF(uom_id = 1, 1, 0))) AS `Average radius`," +
"(SUM(IF(uom_id = 2, value, 0)) / SUM(IF(uom_id = 2, 1, 0))) AS `Average Volume`," +
"(SUM(IF(uom_id = 3, value, 0)) / SUM(IF(uom_id = 3, 1, 0))) AS `Average SA`" +
"from measurements" +
"WHERE image_id = " + self.dbImage.id.toString() +
"AND status = 'A'" +
"GROUP BY patient_id", self.db)
query.next()
radius_acc = query.value(1).toDouble()
volume_acc = query.value(2).toDouble()
SA_acc = query.value(3).toDouble()
print('average of previously accepted measurements includes ' +
'radius = ' + str(radius_acc) +
'volume = ' + str(volume_acc) +
'SA = ' + str(SA_acc))
具体来说,我想知道我将查询输入到 QSqlQuery 的方式是否有问题?或者我可能试图错误地使用 value(n) 方法?
如果这两种情况都不是,我敢打赌,我在查询中为 self.dbImage.id.toString() 使用了错误的参数,在这种情况下,我明天就问同事。