本帖最后由 zy205817 于 2013-03-28 10:10:32 编辑

解决方案 »

  1.   


    计算思路为:相同的订单号,(20/60)*700,(40/60)*700 ,不同订单号直接取price值。是这样的。700是相同订单price相加得到的。60为相同订单cost3相加得到的。
      

  2.   

    本帖最后由 xuzuning 于 2013-03-28 11:24:48 编辑
      

  3.   

     select a.order_id ,
     (select (a.cost3/sum(cost3) * sum(price))  from od where order_id=a.order_id group by order_id) as price
     from od a;
      

  4.   

    select a.order_id ,
     (select (a.cost3/sum(cost3) * sum(price)),sum(price)  from od where order_id=a.order_id group by order_id) as price
     from od a;但是为什么加了个sum(price) 提示:Operand should contain 1 column(s)
      

  5.   

    里面的子查询有两个字段,那样写是不行的
    select a.order_id ,
     (select (a.cost3/sum(cost3) * sum(price))  from od where order_id=a.order_id group by order_id) as price,
    (select sum(price)  from od where order_id=a.order_id group by order_id) as sum_price
     from od a;