use*_*872 5 sql database ms-access
我在MS Access 2003中工作.
我有表格记录这种结构:
ID, Origin, Destination, Attr1, Attr2, Attr3, ... AttrX
for example:
1, 1000, 1100, 20, M, 5 ...
2, 1000, 1105, 30, F, 5 ...
3, 1001, 1000, 15, M, 10 ...
...
Run Code Online (Sandbox Code Playgroud)
我也有表格,其中包含起源和目的地代码
Code, Country, Continent
1000, Albania, Europe
1001, Belgium, Europe
...
1100, China, Asia
1105, Japan, Asia
...
Run Code Online (Sandbox Code Playgroud)
我需要的是获得2个表,这些表将根据与我指定的属性相关的标准计算记录,但按以下方式分组:
1.原始大陆和目的地大陆
2.原始大陆和目的地国家
例如:
情况1.
Origin, Destination, Total, Females, Males, Older than 20, Younger than 20, ...
Europe, China, 300, 100, 200, 120, 180 ...
Europe, Japan, 150, 100, 50, ...
...
Run Code Online (Sandbox Code Playgroud)
案例2.
Origin, Destination, Total, Females, Males, Older than 20, Younger than 20, ...
Europe, Asia, 1500, 700, 800 ...
Asia, Europe, 1200, ...
...
Run Code Online (Sandbox Code Playgroud)
可以这样做,这样我就可以轻松地添加更多列/标准吗?
情况1:
select count(1) as total ,t2.continent,t3.country,t1.attr1,t1.attr2,t1.attr3 ... t1.attrX from table1 t1
join table2 t2 on t1.origin = t2.code
join table3 t3 on t1.destination = t3.code
group by t2.continent,t3.country,t1.attr1,t1.attr2,t1.attr3 ... t1.attrX
order by total desc
Run Code Online (Sandbox Code Playgroud)
案例2:
select count(1) as total ,t2.continent,t3.continent,t1.attr1,t1.attr2,t1.attr3 ... t1.attrX from table1 t1
join table2 t2 on t1.origin = t2.code
join table3 t3 on t1.destination = t3.code
group by t2.continent,t3.continent,t1.attr1,t1.attr2,t1.attr3 ... t1.attrX
order by total desc
Run Code Online (Sandbox Code Playgroud)