Count of table column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hgriva
    New Member
    • Aug 2006
    • 8

    Count of table column

    Hi,
    i have a table xx with column flg.

    it has values like

    flg
    ----
    T
    G
    T
    T
    G
    G
    G
    G

    I want to write a query that would retrieve
    count(flg) where flg='G'
    and count(flg) where flg='T'
    in a single line query.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by hgriva
    Hi,
    i have a table xx with column flg.

    it has values like

    flg
    ----
    T
    G
    T
    T
    G
    G
    G
    G

    I want to write a query that would retrieve
    count(flg) where flg='G'
    and count(flg) where flg='T'
    in a single line query.
    [code=oracle]
    SELECT flg,COUNT(flg) from xx GROUP BY flg;

    SELECT (SELECT COUNT(flg) from xx WHERE flg = 'G') G, (SELECT COUNT(flg) from xx WHERE flg = 'T') T FROM DUAL;

    [/code]

    Comment

    • hgriva
      New Member
      • Aug 2006
      • 8

      #3
      Originally posted by amitpatel66
      [code=oracle]
      SELECT flg,COUNT(flg) from xx GROUP BY flg;

      SELECT (SELECT COUNT(flg) from xx WHERE flg = 'G') G, (SELECT COUNT(flg) from xx WHERE flg = 'T') T FROM DUAL;

      [/code]
      Hi,
      Thanks for your reply.
      I need one more clarification.

      if want count of flg where flg='G' and count of flg <>'G'
      how would i get it

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by hgriva
        Hi,
        Thanks for your reply.
        I need one more clarification.

        if want count of flg where flg='G' and count of flg <>'G'
        how would i get it
        Also try to use DECODE for the purpose.

        Comment

        • amitpatel66
          Recognized Expert Top Contributor
          • Mar 2007
          • 2358

          #5
          Originally posted by hgriva
          Hi,
          Thanks for your reply.
          I need one more clarification.

          if want count of flg where flg='G' and count of flg <>'G'
          how would i get it
          Give a try to find a count for flg <> G using the ideas from the above post. Post back in case of any issues you face!!

          Comment

          • hgriva
            New Member
            • Aug 2006
            • 8

            #6
            Thanks.I got the answer

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Originally posted by hgriva
              Thanks.I got the answer
              We appreciate that!!...

              Comment

              Working...