$sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'");我想获取 YR_SC 的最大值,是否是这样获取?<?php echo $row['YR_SC']; ?>输出的时候显示错误!

解决方案 »

  1.   

    $sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'");$row=mysql_fetch_array($sql) $row=mysql_fetch_assoc($sql);要先这样 看下手册这两个函数的用法
    <?php echo $row['YR_SC']; ?>
      

  2.   

    $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)."'");
    while($row=mysql_fetch_array($sql)){
        echo $row['MaxYR_SC'];
    }
      

  3.   


    $sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'");
    while($row=mysql_fetch_array($sql)){
        $rows[] =  $row;
    }
    print_r($rows);   //查看数组的结构把所有的记录保存为一个二维数组 用foreach for循环就能得到所有的值
      

  4.   


    $sql=mysql_query("select YR_SC ,CODE,PAR,PRC_N,PRC_U 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)){
        echo $row[0];
        echo $row[1];
        echo $row[2];
        echo $row[3];
        echo $row[4];}
      

  5.   

    and not exists (select 1 from bse_prc_p where CDE_L = a.CDE_L and yr_sc > a.yr_sc)");
    不存在CDE_L相同但yr_sc更大的记录---那这条就是最大的。
    慢的话可以在 CDE_L上建索引试试。