我有这个脚本在mysql db中隐藏NULL值,但是EMPTY值总是计算它们...所以我怎么能隐藏这个值呢?
<table class="table table-bordered table-striped table-condensed bootstrap-datatable datatable" >
<thead>
<tr>
<th>Diagnósticos</th>
<th class="center sorting_desc">Casos vistos</th>
</tr>
</thead>
<tbody>
<?
$sql = $conn->prepare("select diagnostico, count(diagnostico) from ( select diagnostico as diagnostico from DIAGNOSTICON WHERE id_doctor = $id_doctor union all select diagnostico1 as diagnostico from DIAGNOSTICON union all select diagnostico2 as diagnostico from DIAGNOSTICON union all select diagnostico3 as diagnostico from DIAGNOSTICON) t group by t.diagnostico order by count(diagnostico) desc ");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>\n";
echo "<td>";
if (!empty($row["diagnostico"]))
{
echo $row["diagnostico"]."</td>\n"; }
echo "<td>";
if (!empty($row["count(diagnostico)"]))
{
echo $row["count(diagnostico)"]."</td>\n";
echo "</tr>\n"; }
}
?>
</tbody>
</table>
答案 0 :(得分:0)
替换
count(diagnostico)
与
count(case when diagnostico = '' then NULL else diagnostico end)