0

我有这个脚本可以在 mysql db 中隐藏 NULL 值,但是使用 EMPTY 值总是计算它们......所以我怎样才能隐藏这个值呢?

<table class="table table-bordered table-striped table-condensed bootstrap-datatable datatable" >
    <thead>
        <tr>
            <th>Diagn&oacute;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>
4

1 回答 1

0

代替

count(diagnostico)

count(case when diagnostico = '' then NULL else diagnostico end)
于 2013-07-17T17:22:09.217 回答