两张表,table1,score
table1的ID对应accountScore的ID,accountScore的score的值是decm/(decm的和)
若accountScore的表,ID为1的score的值就为20/(20+30+40+50)
这个存储过程怎么写?table1
id  decm
1    20
2    30
3    40
4    50
...  ...accountScore
id  score  

解决方案 »

  1.   

    update accountScore a set a.score=(select decm from table1  where id=a.id)/(select sum(decm) from table1)  
      

  2.   

    抱歉题目有点没说清楚,这个存储过程的作用,就是每次对table1增删改的时候更新accountScore的score字段。hdhmail2000 
    我之前也是像你这么写的,可是score总是为0,是不是字段的类型不对?我用的是double,float都试过,都为0.
      

  3.   

    你先查询结果出来看看是不是查询结果有问题
    select   b.decm   from   accountScore a,table1 b,     where   a.id=b.id
    select   sum(decm)   from   table1
      

  4.   

    查询结果是没问题的,我刚试直接从表里面插数据了,结果DOUBLE类型的字段,输入小数都为0,float也是,郁闷了
      

  5.   

    看手册中得内容:
    FLOAT[(M,D)] [UNSIGNED] [ZEROFILL] A small (single-precision) floating-point number. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system. 
    DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL] A normal-size (double-precision) floating-point number. Allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system. 
      

  6.   

    问题解决了,double的十进位没设置好,谢谢各位了,结贴