How to find power of a number in SQLite

前端 未结 7 1842
悲&欢浪女
悲&欢浪女 2020-12-09 17:39

I want to update the Interest field in my database. My SQL query is like as per below

Update Table_Name set Interest = Principal * Power(( 1 + (rate

7条回答
  •  时光说笑
    2020-12-09 18:27

    This could be solved with SQL. This works for integer exponents:

    Drop Table if Exists args ;
    Create Table args as Select 2.5 as Base, 4 as Exponent ;
    
    WITH RECURSIVE pow(exponent, exponent_remainder, base, result) as (
        --FIRST EXPRESSION
        SELECT exponent,exponent -1 , base,base
        FROM args
        
        union all 
        --SECOND EXPRESSION
        select Args.exponent,pow.exponent_remainder -1, pow.base,pow.result * pow.base
        from args
        join pow on args.exponent = pow.exponent
        where pow.exponent_remainder >= 0
    )
    select pow.result
    from pow
    where pow.exponent_remainder = 0;
    

提交回复
热议问题