$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)之后,上面的值就没法循环了?
这个该怎么解决?
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)之后,上面的值就没法循环了?
这个该怎么解决?
分组,就是GROUP BY
很纠结
但是
$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