I'm trying to get the count(physician.id) but I'm getting errors in rails.

```
class Physician < ApplicationRecord
 has_many :appointments
 has_many :patients, through: :appointments
end

class Appointment < ApplicationRecord
 belongs_to :physician
 belongs_to :patient
end

class Patient < ApplicationRecord
 has_many :appointments
 has_many :physicians, through: :appointments
end

```

and what I'm doing here is:

```
patients_count = Patient.joins(:physicians).includes(:physicians).select('count(physician.id) as count').group('patients.id').paginate(page: params[:page], per_page: 25) 

```

I'm getting this error, `"PG::SyntaxError: ERROR: syntax error at or near "as"
LINE 1: ...CT COUNT(DISTINCT count(physician.id) as count)"`

not sure if pagination is causing this issue, how to solve it?