update t_cg_Rkdmx set cBcsl=90.0+cBcsl-(select distinct Sl from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1') where cDjbh='CGRK-20041014-00001' and cXh='1'

解决方案 »

  1.   

    不行啊,错误依旧,拜托了,我sql很菜
      

  2.   

    報錯是因為select Sl from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1'查詢出來的值不只一個﹐有多個﹔根據你的實際情況﹐你可選擇排序后取第一個來更新update t_cg_Rkdmx set cBcsl=90.0+cBcsl-(select top 1 Sl from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1' order by Sl desc) where cDjbh='CGRK-20041014-00001' and cXh='1'
      

  3.   

    系统提示已经很清楚了,子查询select Sl from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1'返回了多条记录。update t_cg_Rkdmx set cBcsl=90.0+cBcsl-(select TOP 1 Sl from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1') where cDjbh='CGRK-20041014-00001' and cXh='1'
    --满足Czdjbh='CGRK-20041014-00001' and Czmxbh='1'的头一条记录的Sl值或
    update t_cg_Rkdmx set cBcsl=90.0+cBcsl-(select MAX(Sl) from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1') where cDjbh='CGRK-20041014-00001' and cXh='1'
    --满足Czdjbh='CGRK-20041014-00001' and Czmxbh='1'的最大Sl值或
    update t_cg_Rkdmx set cBcsl=90.0+cBcsl-(select MIN(Sl) from t_cg_Thdmx where Czdjbh='CGRK-20041014-00001' and Czmxbh='1') where cDjbh='CGRK-20041014-00001' and cXh='1'
    --满足Czdjbh='CGRK-20041014-00001' and Czmxbh='1'的最小Sl值如果满足条件Czdjbh='CGRK-20041014-00001' and Czmxbh='1'的不应该有多个记录,那就要你自己手工检查一下了。