0
Task.select('task_name, id, COUNT(*) AS cnt').group(:task_name).having('cnt > 1')

What's wrong with this query I getting error like : PG::UndefinedColumn: ERROR: column "cnt" does not exist

Please Help me in this query.

Thanks In Advance

1
  • 2
    What does .to_sql return for that? Commented May 10, 2014 at 4:04

1 Answer 1

1

Try (note the duplication of the function in the having clause):

Task.select("..., COUNT(*) AS cnt").group("...").having("COUNT(*) > 1")

From: http://www.postgresqltutorial.com/postgresql-having/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.