I’m having an absolute brain breakdown with this SQL query, I’m hoping someone can shine some light with what I should be doing.
I have the following tables and they are linked by “anumber”;
athletes
--------
anumber (id)
acountry ('Australia','Japan')
aname
result_placing
--------------
result_id id
anumber (id linked to athletes)
result_placing (Gold, Silver or null)
I would like to get a list of countries with how many gold, silver results associated. so output like:
country | resul_placing | result_count
----------- | ------------- | ------------
Australia | Gold | 2
Australia | Silver | 1
I tried something like this:
SELECT acountry
FROM athletes
INNER JOIN result_placing
ON athletes.anumber = result_placing.anumber
Which shows
Australia | Gold |
Australia | Silver |
Just not sure how to get the count of each. I tried count(distinct) but Access doesn’t like it.
As soon as I use Count in it like:
SELECT a.acountry
, r.placing
, count(a.acountry)
FROM athlete a
INNER JOIN result_place r
ON a.anumber = r.anumber
I receive:
You tried to execute a query that does not include the specified expression 'acountry' as part of an aggregate function
Try