COUNT in WHERE statment

  • How can I query this:   

    select count(doc_iccmc) cnt,doc_iccmc from v_DOCUMENTDIRECTORY

    where cnt >2

    group by doc_iccmc

     

    It errors. I guess cause CNT isn't a "real" column. How do you use COUNT in a where statment? Thanks.

     

     

  • Shouldn't the query be:

    select count(doc_iccmc) cnt,doc_iccmc from v_DOCUMENTDIRECTORY

    where count(doc_iccmc) >2

    group by doc_iccmc

     

    mom

  • select count(doc_iccmc) cnt,doc_iccmc from v_DOCUMENTDIRECTORY

    group by doc_iccmc

    Having count(doc_iccmc) > 2

  • Remi,

    Your solution would be right.  Hm I guess I should stop to think for a second before trying to answer.

     

    mom

  • I was rereading your post and didn't see any difference... Was wondering if I were going blind all of a sudden.

    Anyways, I think I would use Count(*) if case permits... allows more options to the query optimizer.

  • Of course the lovely  HAVE clause.

    Thanks MOM and Remi. Much appreciated.

  • HTH.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply