Sum of values of a bd column between a time interval - PHP

Asked

Viewed 84 times

2

include "conexao.inc";

$sql="SELECT * FROM tb_abastece WHERE data BETWEEN ('20/01/2019') AND ('30/01/2019')";          
$res=mysqli_query($conexao,$sql); 

while($vreg=mysqli_fetch_array($res))
{
    $id=$vreg[0];
    $ida=$vreg[1];
    $postoa=$vreg[2];
    $insumoa=$vreg[3];
    $valora=$vreg[4];
    $kmlta=$vreg[5];
    $dataa=$vreg[6];
    $ltsa=$vreg[7];
    $destinoa=$vreg[8];
    $odometroa=$vreg[9];
    $kma=$vreg[10];
}
<div>
    echo $id." / ".$postoa." // ".$kmlta."  // ".$destinoa; 
</div>

I want the column total ltsa between an initial date and a final date. I got the break, but I don’t know how to add.

I appreciate any help.

1 answer

1


Try this:

SELECT SUM(t.ltsa)
FROM tb_abastece t
WHERE t.data BETWEEN '2019-01-20' AND '2019-01-30'

Obviously, this will only bring up a column as a result, which is the sum. You will only get the result of this column in the while.

  • Looking at it like this, it seems to me that 02/25/2014 will be between there, at least it seems to be string format. Dates on my as far as I know (I didn’t use 8) are yyyy-mm-dd, no?

  • 1

    @Bacco Arrumado.

  • There is still hope for Anna’s column to be in date format too, otherwise it will still be a problem, even with the conversions (but only with an edition in the question by the person who posted it).

  • 1

    Thanks, it worked out

Browser other questions tagged

You are not signed in. Login or sign up in order to post.