SQL中格式化列的总和

时间:2016-02-15 05:13:01

标签: mysql sql

示例表:

ID Calls
1   10
2   20
3   15
4   11
5   09

Output Needed:

  ID Calls  Percent
    1   10    15.38
    2   20    30.77
    3   15    23.08
    4   11    16.92
    5   09    13.85

“调用”列已经是格式化列。 format(count(id),0) as Calls

即通过使用公式找到值。现在我想制作一个第3列,它将显示Calls的%值。

SUM(呼叫)不能用作“呼叫”是手动提供的名称。应该如何使用MySQL查询?

1 个答案:

答案 0 :(得分:1)

如果没有错,你需要这样的东西

如果您的数据库支持import numpy as np from scipy.integrate import odeint A = np.logspace(-2, 2, 5, 10) lenA = len(A) B = 2*np.logspace(-4, 1, 6, 10) lenB = len(B) S0plot = np.zeros((lenA,lenB)) S1plot = np.zeros((lenA,lenB)) KS0plot = np.zeros((lenA,lenB)) PS1plot = np.zeros((lenA,lenB)) Kplot = np.zeros((lenA,lenB)) Pplot = np.zeros((lenA,lenB)) y0 = [0] * 6 ydot = np.zeros((6,1)) def f(y): for Bloop in range(lenB): for Aloop in range(lenA): A0 = A[Aloop] Q = B[Bloop] r1 = 2e-5 r2 = 2e-4 a = 0.001 d = 0.001 k = 0.999 P0 = 1 tf = 1e10 time = np.linspace(0, tf, 1001) S00 = Q/r1 S0 = y[0] S1 = y[1] KS0 = y[2] PS1 = y[3] K = y[4] P = y[5] ydot[0] = Q-r1*S0+d*KS0-a*K*S0+k*PS1 ydot[1] = k*KS0+d*PS1-S1*(r1+a*K+a*P) ydot[2] = a*K*S0-(d+k+r1)*KS0 ydot[3] = a*P*S1-(d+k+r1)*PS1 ydot[4] = (d+k+r1)*(KS0)-a*K*(S0+S1) ydot[5] = (d+k+r2)*PS1-a*P*S1 return ydot[:,0] y0[0] = S00 y0[1] = 0 y0[2] = 0 y0[3] = 0 y0[4] = A0 y0[5] = P0 soln = odeint(f, y0, time, mxstep = 5000) S0 = soln[:,0] S1 = soln[:,1] KS0 = soln[:,2] PS1 = soln[:,3] K = soln[:,4] P = soln[:,5] S0plot[Aloop,Bloop] = soln[len(time)-1,0] S1plot[Aloop,Bloop] = soln[len(time)-1,1] KS0plot[Aloop,Bloop] = soln[len(time)-1,2] PS1plot[Aloop,Bloop] = soln[len(time)-1,3] Kplot[Aloop,Bloop] = soln[len(time)-1,4] Pplot[Aloop,Bloop] = soln[len(time)-1,5] Stot = S0plot + S1plot + KS0plot + PS1plot Stot = f(y) print(Stot) 功能。

window

传统SELECT id, calls, cast(calls as numeric(15,6)) / NULLIF(Sum(Calls)OVER(), 0) FROM yourtable 方式

SQL