我对这个 SQL 查询彻底崩溃了,我希望有人能对我应该做的事情有所启发。
我有以下表格,它们由“anumber”链接;
athletes
--------
anumber (id)
acountry ('Australia','Japan')
aname
result_placing
--------------
result_id id
anumber (id linked to athletes)
result_placing (Gold, Silver or null)
我想获得与多少金、银结果相关的国家列表。所以输出如下:
country | resul_placing | result_count
----------- | ------------- | ------------
Australia | Gold | 2
Australia | Silver | 1
我试过这样的事情:
SELECT acountry
FROM athletes
INNER JOIN result_placing
ON athletes.anumber = result_placing.anumber
这表明
Australia | Gold |
Australia | Silver |
只是不确定如何获得每个的计数。我试过 count(distinct) 但 Access 不喜欢它。
一旦我在其中使用 Count ,就像:
SELECT a.acountry
, r.placing
, count(a.acountry)
FROM athlete a
INNER JOIN result_place r
ON a.anumber = r.anumber
我收到:
You tried to execute a query that does not include the specified expression 'acountry' as part of an aggregate function