out_warehouse 商品信息表 out_id out_original out_date out_remark out_total_amount oo003736c6a2bb433bb9ccea208d4f79dc 201512WMPK36 2015/12/21 孟庄市场公厕维修 103.83 oo00ef4d50e66f43d0bc2cd5e262c4075e 201512WMPK22 2015/12/20 广场维修费用 2000 out_warehouse_detail 商品明细表 out_id out_total_price oo003736c6a2bb433bb9ccea208d4f79dc 70 oo003736c6a2bb433bb9ccea208d4f79dc 3.83 oo003736c6a2bb433bb9ccea208d4f79dc 30 oo00ef4d50e66f43d0bc2cd5e262c4075e 800 oo00ef4d50e66f43d0bc2cd5e262c4075e 200
out_warehouse 和 out_warehouse_detail 通过主外键 out_id相互关联
需要实现效果:
解决方案
18
select out_warehouse .*,sum(out_total_price) as total from out_warehouse left join out_warehouse_detail on out_warehouse .out_id=out_warehouse_detail .out_id group by out_warehouse_detail .out_id 试试看
6
SELECT a.out_id,a.out_original,a.out_date,a.out_remark,a.out_total_amount,b.out_total_price FROM out_warehouse a
JOIN
(SELECT out_id,sum(out_total_price) as out_total_price FROM out_warehouse_detail GROUP BY out_id) b
ON a.out_id = b.out_id;
JOIN
(SELECT out_id,sum(out_total_price) as out_total_price FROM out_warehouse_detail GROUP BY out_id) b
ON a.out_id = b.out_id;
6
select a.out_id,a.out_original,a.out_date,a.out_remark,a.out_total_amount,sum(b.out_total_price)
from out_warehouse a,out_warehouse_detail b
where a.out_id=b.out_id
group by a.out_id
不知道能否是本人想的太简单了
from out_warehouse a,out_warehouse_detail b
where a.out_id=b.out_id
group by a.out_id
不知道能否是本人想的太简单了
6
select out_id,out_original,out_date,out_remark,out_total_amount, (select sum(out_total_price) from out_warehouse_detail where out_id=out_warehouse.out_id) as out_total_price from out_warehouse