sql query reg count of column values

  • I have a table with 2 columns: AgrNo and RowFlag. RowFlag can have 2 values ie 'Y' or 'N'. I would like to count the number the total 'y' and 'N' for a corresponding AgrNo.

    Resultant set will have 3 columns: Agrno, CountOf(Y) and CountOf(N).

    countOf(Y) : will have the count of RowFlag with value as 'y' for an AgrNo

    countOf(N) : will have the count of RowFlag with value as 'N' for an AgrNo

    any suggestions how to go about it

  • SELECTagrNo,

    SUM(CASE WHEN rowFlag = 'Y' THEN 1 ELSE 0 END) AS countOfY,

    SUM(CASE WHEN rowFlag = 'N' THEN 1 ELSE 0 END) AS countOfN

    FROMTable1

    GROUP BYagrNo


    N 56°04'39.16"
    E 12°55'05.25"

  • the suggestion helped. Thanks a ton.

Viewing 3 posts - 1 through 2 (of 2 total)

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