1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Need help on count

Discussion in 'SQL PL/SQL' started by eric_A, Mar 3, 2017.

  1. eric_A

    eric_A Starter

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    Philippines
    Hi Folks,

    I'm a beginner in oracle and I need some help. I have a table tha would look like below.

    LOT WFID
    G3AR95 G3AR95_01
    G3AR95 G3AR95 _02
    G3AR95 G3AR95_03
    H4AR96 H4AR96_12
    H4AR96 H4AR96_20

    Basically I just wanted to count the number of WFID associated to a LOT:
    The report would look like this. How to achieve this using sql?

    LOT WF_Count
    G3AR95 3
    H4AR96 2
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,566
    Likes Received:
    362
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    You need to understand this is a query requiring the GROUP BY clause which 'collects' like values in a column so they can be counted. Your query would look like:

    select a, count(b)
    from c
    group by a;

    For the following sample data:

    a b

    1 1
    1 2
    1 3
    2 1
    2 2


    the results would be:

    a count(*)
    1 3
    2 2


    Use that example to write your query.