$sql=mysql_query("select MAX(YR_SC) as MAX_Y ,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=MAX_Y");我将{ MAX(YR_SC) as MAX_Y } YR_SC 的最大值 赋值给 MAX_Y ,输出的时候可以显示,但是我在语句最后加了一个条件YR_SC=MAX_Y 的时候为什么就不显示东西了? 请教一下,最近发了很多类似的帖子,都是搞不定思路,然后又换了一种思路
有没有更好的赋值方法?
有没有更好的赋值方法?
select YR_SC as MAX_Y ,CODE,PAR,PRC_N,PRC_U from bse_prc_p as t
where CDE_L='".substr($code,0,11)."'
and YR_SC=(select max(YR_SC) from bse_prc_p where CODE=t.CODE)
$sql=mysql_query("select MAX(YR_SC) as MAX_Y from bse_prc_p where CDE_L='".substr($code,0,11)."'");
$sql1=mysql_query("select YR_SC,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC='MAX_Y' ");我试了,怎么还是不行啊?
$sql=mysql_query("select MAX(YR_SC) as MAX_Y ,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=MAX_Y");第一个红字还没有得到,第二个都开始用了你说可以么?他肯定是找不到这个东西了
$sql=mysql_query("select MAX(YR_SC) as MAX_Y ,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=(select MAX(YR_SC) from bse_prc_p where CDE_L='".substr($code,0,11)."')");
$link=@mysql_connect("localhost","root","root") or die ("数据库链接失败".mysql_error());
mysql_select_db("bse",$link);
mysql_query("set names gb2312");
$sql=mysql_query("select max(YR_SC) as MAX_Y from bse_prc_p where CDE_L='".substr($code,0,11)."'");
$sql1=mysql_query("select YR_SC,CODE,PAR,PRC_N,PRC_U,sum(PRC_N) from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC='MAX_Y' "); while($row=mysql_fetch_array($sql1)){ ?>
<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>
<?php
}
mysql_close($link);
?>
能不能看下这个代码 哪地方出错了? 就是不显示数据
$sql=mysql_query("select MAX(YR_SC) as MAX_Y ,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=(select max(YR_SC) from bse_prc_p)");
不知道这样行不行,你可以试试:
$sql=mysql_query("select CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=(select MAX(YR_SC) from bse_prc_p)");
通过GROUP BY CODE 确实可以将 YR_SC=最大值的记录都显示出来,但是如果我想加一个条件:在上面的条件的基础上 计算PRC_N 所有记录的和该怎么做?
$sql=mysql_query("select MAX(YR_SC) as MAX_Y ,CODE,PAR,PRC_N,PRC_U,sum(PRC_N) from bse_prc_p where CDE_L='".substr($code,0,11)."' and YR_SC=(select max(YR_SC) from bse_prc_p) GROUP BY CODE");这样是不行的
请问一下啊,有啥办法没有?
该如何做?
郁闷
再清晰的描述一下你的需求max、sum 等函数默认只会产生一条查结果
是否够详细?不用GROUP BY
如果用 group by 的话,sum的值就不对了
有没有什么办法解决?
我用两个语句也不对,就删掉了
select MAX(YR_SC),sum(PRC_N) from bse_prc_p where ...试试吧,应该可以