if($guihuan_search=='全部已还'){ $sql_s="select dh,count(*) AS all_nums,SUM(CASE WHEN zhuangtai = '已归还' THEN 1 ELSE 0 END) AS yiguihuan from dangxiao_zichan_jieyong_list where zhangtao='001' GROUP BY dh HAVING yiguihuan=all_nums "; $result_s=$mysqli->query($sql_s); $pm_str=''; while ($rs_s=$result_s->fetch_assoc()){ $pm_str=$pm_str."'".$rs_s["dh"]."',"; } if (str_replace(',','',$pm_str)!=''){ $pm_str="(".substr($pm_str,0,-1).")"; $z_sql_str.=" and ( dh in ".$pm_str." ) "; }else{ $z_sql_str.=" and ( dh in ('XXX') ) "; } } select dh,count(*) AS all_nums,SUM(CASE WHEN zhuangtai = '已归还' THEN 1 ELSE 0 END) AS yiguihuan from jieyong_list where zhangtao='001' GROUP BY dh HAVING yiguihuan>0 select dh,count(*) AS all_nums,SUM(CASE WHEN zhuangtai = '已归还' THEN 1 ELSE 0 END) AS yiguihuan from jieyong_list where zhangtao='001' GROUP BY dh HAVING yiguihuan=all_nums //如果状态='已归还' 则 yiguihuan+1 SUM(CASE WHEN zhuangtai = '已归还' THEN 1 ELSE 0 END) AS yiguihuan //group by dh单独用将dh独立分组显示,加上having则增加限定条件 GROUP BY dh HAVING yiguihuan>0
以上就是计算符合条件的记录数并按条件显示的详细内容,更多关于计算符合条件的记录数并按条件显示的资料请关注九品源码其它相关文章!