I have two tables: company and truck
In the table, I have the data entry fields, datasaida, valordiaria I would like to select all the companies, and list it and the total amount that the company spent on daily, only if the datasaida is different from '0000-00-00 00:00:00' in case. If you did not complete the daily rate, type 1 day and 20 hours for example, the daily rate is counted the same. Always rounded up.
I'm using PHP. I'm stuck with this SQL that first needs to figure out how many days I've spent in total for each truck, then do the daily rate, then add up all the totals and generate the total that was spent by each company.
$sql = mysql_query("SELECT * FROM empresa WHERE emp_ativo = '1' ORDER BY emp_nome ASC");
while ($linha = mysql_fetch_assoc($sql)){
$sql_valor = mysql_query("SELECT * FROM caminhao WHERE cam_ativo = '1' AND emp_id = '".$linha['emp_id']."' AND cam_datasaida != '0000-00-00 00:00:00'");
while ($val = mysql_fetch_array($sql_valor)){
...
}
$lista[] = $linha;
}