mysql + PDO中的每日销售量和用户数量

时间:2013-06-20 00:46:31

标签: mysql pdo report

我不知道管理员(医生)每天如何显示每天的用户数量(pacientes)... 我有这个每日报告,它打印出我每天的总销售量,但如果我需要显示用户数量(pacientes),他看到(如10 pacientes)代码打印2000或更多..

你可以帮我解决这个问题吗?

<table class="table table-bordered table-striped table-condensed">
    <thead>
        <tr>
          <th>Fecha</th>
          <th>Total Pacientes vistos</th>
          <th>Total diario</th>                                 
        </tr>
    </thead>   
    <tbody>
        <tr>
            <? 
                include 'config.php';
                $sql = $conn->prepare("SELECT DATE(start) AS date, SUM(id_paciente) AS total_pacientes, SUM(honorario) AS total_diario
                FROM CITAS WHERE start >= CURDATE() AND start < CURDATE() + INTERVAL 1 DAY ORDER BY start ASC");
                $sql->execute();
                while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
            ?>
            <td class="center"><? echo $row['date']; ?></td>
            <td class="center"><? echo $row['total_pacientes']; ?></td>
            <td class="center"><? echo $row['total_diario']; ?></td>                 
        </tr>   <? } ?>                          
    </tbody>
</table> 

表CITAS

  • 开始 datetime
  • honorario varchar
  • id_paciente int

我需要报告显示如下:

date(fecha)-------- total_user(total de pacientes)----- total_sales(total diario)

  • 10 JUNIO-2013 ---------- 25 ------------------------------- --650.00
  • 09-JUNIO-2013 ---------- 10 ------------------------------- --250.00
  • 08-JUNIO-2013 ---------- 15 ------------------------------- --375.00

但是现在就这样表明:

date(fecha)-------- total_user(total de pacientes)----- total_sales(total diario)

  • 10 JUNIO-2013 ---------- 65725 ------------------------------- --650.00
  • 09-JUNIO-2013 ---------- 34510 ------------------------------- --250.00
  • 08-JUNIO-2013 ---------- 49815 ------------------------------- --375.00

id_paciente有17,000个用户,是表PACIENTES的FK

1 个答案:

答案 0 :(得分:1)

问题在于:

SUM(id_paciente) AS total_pacientes

您不想总结ID。你想要算数。替换为:

count(id_paciente) AS total_pacientes