[resolved] Problem Trying to Sum SQL decimals with specific ID (2 posts)

  1. Daniel McClure
    Posted 2 years ago #

    I am trying to add up all the values within a decimal column where the ID is equal to a queried ID. I have tried many solutions and nothing seems to work. The current solution seems to provide an answer however it is the wrong one.

    /* Sum payments made to invoice number */
    $payments_table = $wpdb->prefix . "_payments";
    $invoice_id = '999999999';
    $result = $wpdb->query('SELECT sum(value) FROM '.$payments_table.' WHERE invoice_id = '.$invoice_id.'');
    echo $result;

    In the database there are currently two payments of '0.001' for invoice '999999999' so I would expect the sum to be '0.002' however the code returns '1'

  2. Daniel McClure
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic