1){ $orderbydesc=""; $descTXT="↓"; }else{ $orderbydesc=" desc"; $descTXT="↑"; } If ($orderby=="") { $orderby="OA_DepartmentID,OA_User_ID"; $descTXT="↓"; } //查询开始 $sql="select CouponDate,sum(CASE WHEN CouponType=1 then UserInt else 0 end)/4 WxInt,sum(CASE WHEN CouponType=2 then UserInt else 0 end)/4 PcInt from ( select CONVERT(VARCHAR(10),CouponDate,120) CouponDate, (CASE WHEN CHARINDEX('PC',CouponName)>0 then 2 WHEN CHARINDEX('公交广告促销活动',CouponName)>0 then 1 else 0 end) CouponType, COUNT(ToUserID) UserInt from Coupon where CouponDate ".$SqlDateType." GROUP BY CONVERT(VARCHAR(10),CouponDate,120),(CASE WHEN CHARINDEX('PC',CouponName)>0 then 2 WHEN CHARINDEX('公交广告促销活动',CouponName)>0 then 1 else 0 end)) as a1 GROUP BY CouponDate order by CouponDate desc"; //echo $sql;//exit; $data = sqlsrv_query($conn,$sql); if($data == true){ $FormArray=array(); //表头 $FormArray[0]=array("日期","PC数量","小程序扫码数量"); $FormArrayX=count($FormArray[0]); if (sqlsrv_rows_affected($data)==0) { $SystemMessageType=2; $SystemMessageTXT="数据库中相关无数据!"; $y=0; } else { $i=0; while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { //读取数据 $CouponDate = $rs['CouponDate']; $WxInt = $rs['WxInt']; $PcInt = $rs['PcInt']; //读取数据--End //写入数组 $i++; $FormArray[$i][0]=$CouponDate; $FormArray[$i][1]=$PcInt; $FormArray[$i][2]=$WxInt; //写入数组--End } } } //echo print_r($FormArray); //exit; ?>