$sql=mysql_query("select YR_SC ,CODE,PAR,PRC_N,PRC_U,sum(PRC_N) from bse_prc_p a where CDE_L='".substr($code,0,11)."' and not exists (select 1 from bse_prc_p where CDE_L = a.CDE_L and yr_sc > a.yr_sc )");
while($row=mysql_fetch_row($sql)){…………<tr>
    <td height="30" align="left" bgcolor="#E0E0E0"><?php echo substr($row[1],12,3);?></td>
    <td height="30" align="left" bgcolor="#E0E0E0"><?php echo $row[2];?></td>
    <td height="30" align="right" bgcolor="#E0E0E0"><?php echo $row[3]; ?></td>
    <td height="30" align="right" bgcolor="#E0E0E0"><?php echo $row[0]; ?></td>
    <td height="30" align="right" bgcolor="#E0E0E0"><?php echo $row[4]; ?></td>
    <td height="30" align="right" bgcolor="#E0E0E0"></td>
  </tr>我加入sum(PRC_N)之后,上面的值就没法循环了?
这个该怎么解决?

解决方案 »

  1.   

    楼主试一试mysql_num_rows的用法
      

  2.   

    速度慢,大概是因为  and not exists  这种筛选结果的方式
    分组,就是GROUP BY
      

  3.   

    但是去掉 and not exists 这种筛选方式,就没法让YR_SC=最大值的记录循环显示了
    很纠结
      

  4.   

    $sql=mysql_query("select max(YR_SC) as MaxYR_SC,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' GROUP BY CODE ");这样可以让YR_SC的最大值循环显示
    但是
    $sql=mysql_query("select max(YR_SC) as MaxYR_SC,CODE,PAR,PRC_N,PRC_U,sum(PRC_N) as SUMPRC_N from bse_prc_p where CDE_L='".substr($code,0,11)."' GROUP BY CODE ");加了sum(PRC_N) as SUMPRC_N 之后又不能循环显示了,分组的话只能用CODE