一个查询中的SELECT和UPDATE

时间:2012-08-18 11:51:00

标签: mysql sql

我正在尝试执行查询而我不知道如何在不使用存储过程的情况下使其工作,但由于我正在使用的编程语言的限制,其mysql平台将不接受存储过程/函数。

代码是:

select
    (myrpg_faction_info.funds) as bank,
    (
        myrpg_faction_info.paycheckrate +
        myrpg_faction_ranks.paycheckrate +
        sum(myrpg_faction_flags.paycheckrate)
    ) as rate

from 
    myrpg_faction_info
inner join
    myrpg_faction_ranks 
        on 
            myrpg_faction_info.id = myrpg_faction_ranks.fid and 
            myrpg_faction_ranks.rank=1
inner join
    myrpg_faction_flags 
        on 
            myrpg_faction_info.id=myrpg_faction_flags.fid and
            (1 << myrpg_faction_flags.flag) & 1
where myrpg_faction_info.id=1

但是我必须保存rate和bank变量(在SQL中)并更新faction_info表以从faction_info.bank列中取出速率并选择取下的值,但我不知道如何去做

1 个答案:

答案 0 :(得分:0)

update mfi
set myrpg_faction_info.funds -
    (
        myrpg_faction_info.paycheckrate +
        myrpg_faction_ranks.paycheckrate +
        sum(myrpg_faction_flags.paycheckrate)
    ) as rate
from 
    myrpg_faction_info mfi
inner join
    myrpg_faction_ranks 
        on 
            myrpg_faction_info.id = myrpg_faction_ranks.fid and 
            myrpg_faction_ranks.rank=1
inner join
    myrpg_faction_flags 
        on 
            myrpg_faction_info.id=myrpg_faction_flags.fid and
            (1 << myrpg_faction_flags.flag) & 1
where myrpg_faction_info.id=1