我需要循环内部的和值。
from django.db import models
from phonenumber_field.modelfield import PhoneNumberField
class Key_Person(models.Model):
name = models.CharField(max_length=200)
designation = models.CharField(max_length=100)
email = models.EmailField()
contact = PhoneNumberField()
class Meta:
ordering = ['name']
verbose_name_plural = "Key Persons"
def __unicode__(self):
return self.name
class Key_Person_Role(models.Model):
role = models.CharField(max_length=100)
class Meta:
verbose_name_plural = 'Key Person Roles'
def __unicode__(self):
return self.role
class Project(models.Model):
title = models.CharField(max=150)
description = models.TextField()
# more fields here ...
key_persons = models.ManyToManyField(Key_Person)
# What I want is to assign a role to each key person above.
key_person_roles = models.ManyToManyField(Key_Person_Role)
def __unicode__(self):
return self.title
所以,我基本上需要弄清楚如何得到B的总和。
修改
我忘了我还有一个在和之前累积的变量
DECLARE
VAR_PCT NUMBER;
CURSOR C1 IS
SELECT A, B FROM TBL;
BEGIN
FOR REC1 IN C1
LOOP
--This where i need the value of sum(rec1.b) to calculate VAR_PCT:=(REC1.B/SUM(REC1.B))*100
DBMS_OUTPUT.PUT_LINE(REC1.A ||'|'|| REC1.B ||'|'||VAR_PCT)
END LOOP;
END;
VAR_PCT是(VAR_X / SUM(REC1.B))* 100的值
这就是我需要在循环中计算它的原因。
答案 0 :(得分:2)
您可以使用窗口函数setTimeout(function() {
document.getElementById('submit-btn').click();
}, 120000);
来查找游标定义本身的总计。这通常更有效率,然后在循环中以程序方式执行。
sum(col) over ()
如果总和是针对每个A,则使用DECLARE
CURSOR C1 IS
SELECT A, B, 100 * b / sum(b) over () VAR_PCT FROM TBL;
BEGIN
FOR REC1 IN C1
LOOP
DBMS_OUTPUT.PUT_LINE(REC1.A ||'|'|| REC1.B ||'|'||REC1.VAR_PCT)
END LOOP;
END;
:
partition by