21,886
社区成员
发帖
与我相关
我的任务
分享
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;
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) 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;
select cost3, (cost3/sum_cost3)*sum_price as price, a.order_id
form
tbl_name a,
(select order_id, sum(cost3) as sum_cost3, sum(price) as sum_price from tbl_name group by order_id) t
where a.order_id=t.order_id
while($r = mysql_fetch_assoc($rs)) {
$st[$r['order_id']['cost3'] += $r['cost3'];
$st[$r['order_id']['price'] += $r['price'];
}
mysql_data_seek($rs, 0);
while($r = mysql_fetch_assoc($rs)) {
$res[] = ($r['cost3']/$st['cost3'])*$st['price'];
}