Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Unanswered: Using COUNT Function with GROUP BY clause

    Hi Folks!

    I have a table with 3 columns:

    Unit, Month, Percentage

    I need a column something like this:

    SELECT Unit, COUNT(Percentage WHERE Percentage >= 80.00)/COUNT(Percentage) * 100 AS [MyColumn]
    WHERE Month = @Month
    GROUP BY Unit

    I am stuck at implementing a good working solution for this.

    Please note that, the second COUNT function will count all percentages (whether >= 80.00 or <= 80.00)

    Please help.

    Thanks,
    Zain

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    How'bout
    Code:
    COUNT(case when Percentage >= 80.00 then Percentage else null end)/COUNT(Percentage) * 100
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

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