[英]Adding two columns from two different tables
I have two tables with same field types. 我有两个表具有相同的字段类型。 Fields that are common in here are *BG_ID* and Store Number .
此处常见的字段是* BG_ID *和商店编号 。 Now I want to SUM two columns (*total_area* and *total_area_blk*) from two tables and group them by BG_ID .
现在,我想从两个表,并将它们按BG_ID SUM两列(* total_area *和* total_area_blk *)。
The following is what I tried which doesnt work: 以下是我尝试不起作用的内容:
select t.bg_id, t.store_number,sum(a.total_area),sum(b.total_area_blk)
from (select bg_id,store_number,total_area
from temp_Prop_area_block a
where store_number='33665'
union all
select bg_id,store_number,total_area_blk
from temp_Prop_area_BG b
where store_number='33665')
Hope, this helps you! 希望对您有帮助!
SELECT bg_id, store_number, SUM(total_area)
FROM
(
SELECT bg_id, store_number, total_area as total_area
FROM temp_Prop_area_block a
WHERE store_number='33665'
UNION ALL
SELECT bg_id, store_number, total_area_blk as total_area
FROM temp_Prop_area_BG b
WHERE store_number='33665'
) my_view
GROUP BY bg_id, store_number;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.