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
版权声明:除特别声明外,本站所有文章皆是本站原创,转载请以超链接形式注明出处!