$sql =mysql_query("select CTL,CUR_C, min(YR_SC) as dt_l,max(YR_SC) as dt_h, (dt_h - dt_l) as yr,max(PRC_N) as pr_n_h, min(PRC_N) as pr_n_l,max(PRC_U) as pr_u_h,min(PRC_U) as pr_u_l, iif((yr * pr_n_h * pr_n_l)>0,exp(log(pr_n_h/pr_n_l)/(dt_h-dt_l))-1,null) as cgr_n,
iif((yr * pr_u_h * pr_u_l)>0,exp(log(pr_u_h/pr_u_l)/(dt_h-dt_l))-1,null) as cgr_u from bse_prc_p where CODE='".$code."' group by CTL,CUR_C ");
while($row=mysql_fetch_array($sql)){
……这个代码很复杂啊,头疼,能否在SQL里做运算?
这个获取不到记录集!
iif((yr * pr_u_h * pr_u_l)>0,exp(log(pr_u_h/pr_u_l)/(dt_h-dt_l))-1,null) as cgr_u from bse_prc_p where CODE='".$code."' group by CTL,CUR_C ");
while($row=mysql_fetch_array($sql)){
……这个代码很复杂啊,头疼,能否在SQL里做运算?
这个获取不到记录集!
这个错误SELECT CTL, CUR_C, min( YR_SC ) AS dt_l, max( YR_SC ) AS dt_h, (
dt_h - dt_l
) AS yr, max( PRC_N ) AS pr_n_h, min( PRC_N ) AS pr_n_l, max( PRC_U ) AS pr_u_h, min( PRC_U ) AS pr_u_l, iif(
(
yr * pr_n_h * pr_n_l
) >0, exp( log( pr_n_h / pr_n_l ) / ( dt_h - dt_l ) ) -1, NULL
) AS cgr_n, iif(
(
yr * pr_u_h * pr_u_l
) >0, exp( log( pr_u_h / pr_u_l ) / ( dt_h - dt_l ) ) -1, NULL
) AS cgr_u
FROM bse_prc_p
WHERE GROUP BY CTL, CUR_C
LIMIT 0 , 30
我不加条件测试时,
select CTL,CUR_C, min(YR_SC) as dt_l, max(YR_SC) as dt_h, dt_h - dt_l as yr,max(PRC_N) as pr_n_h, min(PRC_N) as pr_n_l,max(PRC_U) as pr_u_h,min(PRC_U) as pr_u_l,if((yr * pr_n_h * pr_n_l)>0,exp(log(pr_n_h/pr_n_l)/(dt_h-dt_l))-1,null) as cgr_n,if((yr * pr_u_h * pr_u_l)>0,exp(log(pr_u_h/pr_u_l)/(dt_h-dt_l))-1,null) as cgr_u from bse_prc_p 提示#1054 - Unknown column 'dt_h' in 'field list'
可是我明明定义了啊
where CODE='".$code."' group by CTL,CUR_C 先在页面输出$code 在把输出替换到where中 再在phpmyadmin中执行
iif((yr * pr_u_h * pr_u_l)>0,exp(log(pr_u_h/pr_u_l)/(dt_h-dt_l))-1,null) as cgr_u from bse_prc_p where CODE='CUCN-JN089S-01' group by CTL,CUR_C
提示#1054 - Unknown column 'dt_h' in 'field list'
还是这个错误