私はこの 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