寻找最有效的查询来汇总两个月客户的费用-有两个表,一个表用于1月,一个表用于2月。
我将执行内部联接还是proc sql?寻求帮助。谢谢!
在上面添加了一张图片,因为当我在下面键入内容时,列的排列不正确。
所需结果:
cust 1 total from both tables
cust 2 total from both tables
cust 3 total from both tables
mo cust $ item
jan cust1 10 shoe
jan cust1 20 coat
jan cust1 30 misc
jan cust2 11 shoe
jan cust2 22 top
jan cust3 30 jean
mo cust $ item
feb cust1 15 misc
feb cust1 20 misc
feb cust1 25 jean
feb cust2 35 jean
feb cust3 12 top
feb cust3 30 top
答案 0 :(得分:0)
只能与表设计一样有效。我认为“ $”不是实际的列名:
select
cust, sum(dollars) as dollars
from (
select cust, dollars from table1
UNION ALL
select cust, dollars from table2
) d
group by
cust