lundi 4 octobre 2021

Catching aggregate column value [duplicate]

There is an sql query that returns the sum of the conversation durations in seconds, and displays this time on the screen

$sqlInnerIntervalTotalCost = 'SELECT SUM(TIME_TO_SEC(duration)) AS totalconversationtime FROM calls WHERE calls.outputuser='.$userid.' AND UNIX_TIMESTAMP(calls.datetimecall)>='.strtotime($periodbegin).' AND UNIX_TIMESTAMP(calls.datetimecall) + TIME_TO_SEC(calls.duration)<='.strtotime($periodend);
            
$resinnerinterval=$pdo->prepare($sqlInnerIntervalTotalCost);
$resinnerinterval->execute();

// $sumuserduratiion = mysqli_fetch_row($operatoridtotalcostquery);

while ($sumuserduration = $resinnerinterval->fetch(PDO::FETCH_ASSOC))
{                   
      echo '30<br>';
      var_dump($sumuserduration);
      $outputusername = $usernamesubscriber;
      $totaltime = $sumuserduration['totalconversationtime'];
      echo $totaltime.' время';
};

As a result , I get this conclusion

sqldebug

Did I correctly specify the SUM(TIME_TO_SEC(duration)) AS totalconversationtime? How can I make the value of the totalconversationtime field not NULL?




Aucun commentaire:

Enregistrer un commentaire