これでどうでしょうか?
rb
1language_count = Question.joins(unit: { subject: { user: :country } })
2 .where(country: { area: 3 })
3 .where(user: { id: 20 })
4 .distinct
5 .count(:language)
生成されるSQLは以下の通りです。
sql
1 (0.4ms)
2 SELECT COUNT(DISTINCT "questions"."language")
3 FROM "questions"
4 INNER JOIN "units" ON "units"."id" = "questions"."unit_id"
5 INNER JOIN "subjects" ON "subjects"."id" = "units"."subject_id"
6 INNER JOIN "users" user ON user."id" = "subjects"."user_id"
7 INNER JOIN "countries" country ON country."id" = user."country_id"
8 WHERE "country"."area" = ? AND "user"."id" = ? [["area", 3], ["id", 20]]