Results 1 to 5 of 5

Thread: Count distinct in group by

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,635

    Count distinct in group by

    This my query to count PR.

    SELECT PR, PROVINCIA, COUNT(PR) FROM TABELLA GROUP BY PR, PROVINCIA

    in field PR have a duplicate valute.
    How to count a distinct PR?

    Tks

    Tks

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,608

    Re: Count distinct in group by

    Which Database-system?

    And when PR is a duplicate, is PROVINCIA a duplicate, too?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,635

    Re: Count distinct in group by

    Quote Originally Posted by Zvoni View Post
    Which Database-system?

    And when PR is a duplicate, is PROVINCIA a duplicate, too?
    Access

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,635

    Re: Count distinct in group by

    Yes PR and PROVINCIA yes duplicate too

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,608

    Re: Count distinct in group by

    Not tested
    Code:
    SELECT PR, PROVINCIA, COUNT(PR) FROM 
       (SELECT DISTINCT PR, PROVINCIA FROM TABELLA)
    GROUP BY PR, PROVINCIA
    EDIT: You do realize, that COUNT(PR) should return 1 in each case?

    Looking at it, i'm not even sure, that is what you want.....
    Last edited by Zvoni; Jul 9th, 2024 at 07:44 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width