我无法获得 business_code 相同的注册总数。我的代码如下:
SELECT DISTINCT lb.building_code , lb.bus_code, gl.building_name, gl.bus_name, SUM(gl.enrollment) AS enrollment
FROM table1 AS gl
RIGHT OUTER JOIN table 2 AS lb ON gl.building_key = lb.building_key
where gl.bus_name = 'Business'
and gl.year_cd = 2010
GROUP BY lb.building_code, lb.bus_code, gl.building_name, gl.bus_name, gl.enrollment
电流输出:
building_code bus_code bus_name enrollment
4581 0000 Business A 12
4581 0000 Business A 13
4581 0109 Business B 100
4581 0109 Business B 120
4581 0209 Business C 130
4581 0402 Business D 35
期望的输出:
building_code bus_code bus_name enrollment
4581 0000 Business A 25
4581 0109 Business B 220
4581 0209 Business C 130
4581 0402 Business D 35