Count Over Count

Hi, i was looking for some help in regards to understanding the general rule of using the count function. I am trying to build my knowledge of the different functions in order for me to have a better understanding so that I am writing my sql queries in the right way.
What i was looking to find out was trying to understand the count function. As i understand I can apply the following in order to give me a count of a particular set of data.
select number, count(*) AS no_count
from test
group by job_id;What I am trying to understand is if for some reason I wanted to use the results of the "count(*) AS no_count" to give me another set of results i.e. sum all values over 2 for example, would i write it like the following:
select number, count(*) AS no_count,
select count(no_count) having etc...
from test
group by job_id;or is the general rule that I would have to write a select within a select?
If somebody could please help, would really appreciate it. Btw if there is any documentation on using count, as well as using this with other functions i.e. sum than that would be very useful as well.
Thanks in advance.

Solomon, thanks for your help. Apologies if i have not explained my question properly. The problem is that I haven't created the tables and have wrote my sample data and i am then trying to work out solutions before attempting to create the tables etc, which is probably where I am going wrong.
The job_ids can be repeated, first job_count should give me total job counts belonging to each job_id.
For example in your first dataset you have a job count for all jobs i.e. manager has 3 records with 1 job_count. So I would then like a column to give me a total count of job_count for each criteria i.e. manager had 3 total jobs. I have tried to breakdown the dataset you have shown alongwith the extras I am trying to add, to hopefully explain what I am looking for.
JOB               JOB_COUNT       TOTAL_JOB_COUNT               OVER_1
MANAGER                    1                    3                                   0
PRESIDENT                  1                    1                                   1
CLERK                         1                    4                                   0
SALESMAN                  4                    4                                   0
ANALYST                    2                    2                                   0
MANAGER                   1                    3                                   0
MANAGER                   1                    3                                   0
CLERK                        1                    4                                   0
CLERK                        2                    4                                   0
[/CODE]
So this tells from all jobs which job was dealt with first time so in this case it would be the president, the rest of the jobs were repeated.
The total_job_count would be written like:select job, count(*) as TOTAL_JOB_COUNT
but its the over_1 (or sum maybe, not sure) that is based on the results within the total_job_count that I need to look into to find values that equal to 1. Hence I thought I would have to write a count of a count, which is what I am not clear on.
Sorry for the inconvenience, and really appreciate your help and time.
Thanks
Apologies, not sure how to write the resultset as added but appears all over the place.
Edited by: 973436 on 17-Dec-2012 04:06                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Guidance on use of "COUNT(*) OVER () * 5" in a select query.

    Hello Friends,
    I was reading one article, in which one table was created for demo. Following was the statements for there.
    CREATE TABLE source_table
    NOLOGGING
    AS
    SELECT ROWNUM AS object_id
    , object_name
    , object_type
    FROM all_objects;
    INSERT /*+ APPEND */ INTO source_table
    SELECT ROWNUM (COUNT(*) OVER () * 5)+ AS object_id
    , LOWER(object_name) AS object_name
    , SUBSTR(object_type,1,1) AS object_type
    FROM all_objects;
    INSERT /*+ APPEND */ INTO source_table
    SELECT ROWNUM (COUNT(*) OVER() * 10)+ AS object_id
    , INITCAP(object_name) AS object_name
    , SUBSTR(object_type,-1) AS object_type
    FROM all_objects;
    Can anyone please tell me the purpose of *"ROWNUM + (COUNT(*) OVER () * 5)"* in above 2 insert statements, or suggest me some document on that.
    I don't know about its usage, and want to learn that..
    Regards,
    Dipali..

    The insert statements that you have listed are using Oracle Analytic Functions. Some examples of these functions can be found here: [Oracle Analytic Functions|http://www.psoug.org/reference/analytic_functions.html|Oracle Analytic Functions]
    Effectively what that says is the following:
    1. "COUNT(*) OVER ()" = return the number of rows in the entire result set
    2. Multiply that by 5 (or 10 depending on the insert)
    3. Add the current ROWNUM value to it.
    This can be shown with a simple example:
    SQL> edit
    Wrote file sqlplus_buffer.sql
      1  SELECT *
      2  FROM
      3  (
      4     SELECT ROWNUM r,
      5             (COUNT(*) OVER ()) AS ANALYTIC_COUNT,
      6             5,
      7             ROWNUM + (COUNT(*) OVER () * 5) AS RESULT
      8     FROM all_objects
      9  )
    10* WHERE r <= 10
    SQL> /
             R ANALYTIC_COUNT          5     RESULT
             1          14795          5      73976
             2          14795          5      73977
             3          14795          5      73978
             4          14795          5      73979
             5          14795          5      73980
             6          14795          5      73981
             7          14795          5      73982
             8          14795          5      73983
             9          14795          5      73984
            10          14795          5      73985
    10 rows selected.
    SQL> SELECT COUNT(*) from all_objects;
      COUNT(*)
         14795Hope this helps!
    Note the the statements you provided will not actually execute because of the extra "+" signs on either side. I have removed them.

  • Counting Over Last 3500 appearances with Where Clause

    I'm Using Sql Server Studio 2014
    I have a Table containing the following columns:
    AutoId  Assembly_No  [Rank]   
    1          Assembly1       2
    2          Assembly2       1
    3          Assembly1       2
    4          Assembly1       1
    5          Assembly1       0
    6          Assembly2       2
    7          Assembly2       1
    I'm Trying to Run a query that Will count over the last 3500 times that a specific Assembly_No has been that has a rank > 0. For simplicity's sake we can use we can look at the last 2 times that an assembly has been ran. So the results that I'm expecting
    should look like this
    Assembly_NO   Count
    Assembly2        2
    Assembly1        1
    This resulted in assembly2 being counted twice for ids 6 and 7 and only once for ids 4 and 5 because only one rank was > 0. AutoID is an identity column so the most recent values will be determined using this number.
    The query below can count over all of the Assemblies ran, however I'm having trouble only counting over the last 2 for each assembly
    Select Assembly_No, Count(*) as Count
    From TblBuild
    Where Rank > 0
    Group By Assembly_No
    Returns the following 
    Assembly_no  Count
    Assembly2      3
    Assembly1      3

    Looks like this should return what you are expecting:
    --drop table #temp
    create table #temp
    autoid int,
    assembly_no nvarchar(10),
    rank_no int
    insert into #temp (autoid, assembly_no, rank_no) values (1, 'Assembly1', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (2, 'Assembly2', 1)
    insert into #temp (autoid, assembly_no, rank_no) values (3, 'Assembly1', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (4, 'Assembly1', 1)
    insert into #temp (autoid, assembly_no, rank_no) values (5, 'Assembly1', 0)
    insert into #temp (autoid, assembly_no, rank_no) values (6, 'Assembly2', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (7, 'Assembly2', 1)
    select t.assembly_no, count(nullif(t.rank_no, 0))
    from #temp t
    inner join 
    select autoid, rank_no, row_number() over (partition by assembly_no order by autoid desc) as ct
    from #temp
    )x
    on x.autoid = t.autoid
    and x.ct <= 2
    group by t.assembly_no

  • IR Problem with COUNT (*) OVER () AS apxws_row_cnt

    Hi all,
    i have a query wich is ran under 2 seconds when ecexuted in SQL (TOAD),
    when i use this query in an interactive report then it takes minutes.
    When i reviewd the query which APEX is sending to the DB i noticed an additional select clause:
    SELECT columns,
    COUNT ( * ) OVER () AS apxws_row_cnt
    FROM (
    SELECT *
    FROM ( query
    ) r
    ) r
    WHERE ROWNUM <= TO_NUMBER (:APXWS_MAX_ROW_CNT)
    when i remove the COUNT ( * ) OVER () AS apxws_row_cnt then the query is fast again.
    How can i change the IR so that the COUNT ( * ) OVER () AS apxws_row_cnt doesn't appear annymore.
    I removed the pagination (- no pagination selected -)
    I put the query in a new IR report in a new page, the COUNT ( * ) OVER () AS apxws_row_cnt still appears.
    Any suggestions i can try ?
    Regards,
    Marco

    Marco1975 wrote:
    Hi all,
    i have a query wich is ran under 2 seconds when ecexuted in SQL (TOAD), I doubt that.
    I think your query returns many rows. Did you see all the rows in Toad in 2 secs?
    If the answer is NO then the query is not finished after 2 secs. It just showed you the first few rows.
    Almost every tool including apex does the same.
    However if you want to know how many rows are returned then there is no way around doing the whole select until the last row.
    Then the result can be shown.
    APEX or a developer might use something like the analytic function "count(*) over ()" to get this result already on the first row. The database still needs to fetch all the rows. Howeverthe result set is not transported over the network to the client, which might also save a lot of time compared to not doing it on the database level.

  • Barcode counting over groups

    Hi all,
    I am working on a barcode for my invoices print. This barcode counts over the invoices from 1 to 16 and then starts over again. For example if i have a set of 6 invoices each of 3 pages the barcode numbering will be as follows:
    invoice 1 page 1: 1
    invoice 1 page 2: 2
    invoice 1 page 3: 3
    invoice 2 page 1: 4
    invoice 2 page 2: 5
    invoice 5 page 3: 15
    invoice 6 page 1: 16
    invoice 6 page 2: 1
    invoice 6 page 3: 2
    I have tried to solve this with some xsl-fo programming, but i can't get the page-number or total pages per invoice into a variable. So I can't determine how many pages have been printed for previous invoices and which is the next number to print in the barcode.
    Hope you can give me some advice.

    Looks like this should return what you are expecting:
    --drop table #temp
    create table #temp
    autoid int,
    assembly_no nvarchar(10),
    rank_no int
    insert into #temp (autoid, assembly_no, rank_no) values (1, 'Assembly1', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (2, 'Assembly2', 1)
    insert into #temp (autoid, assembly_no, rank_no) values (3, 'Assembly1', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (4, 'Assembly1', 1)
    insert into #temp (autoid, assembly_no, rank_no) values (5, 'Assembly1', 0)
    insert into #temp (autoid, assembly_no, rank_no) values (6, 'Assembly2', 2)
    insert into #temp (autoid, assembly_no, rank_no) values (7, 'Assembly2', 1)
    select t.assembly_no, count(nullif(t.rank_no, 0))
    from #temp t
    inner join 
    select autoid, rank_no, row_number() over (partition by assembly_no order by autoid desc) as ct
    from #temp
    )x
    on x.autoid = t.autoid
    and x.ct <= 2
    group by t.assembly_no

  • Reg: counter over reading .

    what is  "CntrOverReadg"  in the ik01  while creating measurement point counter.
    can any tell me the usage of this.  what data shd i"ve to enter in this cntrOverReadg

    Its counter overflow reading. It describes the maximum possible reading that physical measurement point can measure.
    For example: A car odometer can measure up to 99999 km of distance covered by it. Hence after the car odometer reaches the value of 99999 km it starts again from 0 km. However the total distance covered by the should be 99999 plus the reading after counter over flow.
    Lets say you have provided the counter overflow reading e.g. 99 for any measurement point for which the current counter reading is 10. If you will create the measurement document with reading less than 10 (let say 4) then the system will consider it as counter overflow occurred and will show the total reading as 103 (i.e 99 + 4) and counter reading as 4.
    Hope it helps!
    Regards,
    Saif Ali Momin

  • Cisco WLC AP count over SNMP

    Hi,
    Is it possible to monitore a quantity of AP on Cisco WLC and quantity of wireless clients?
    I was found only list of AP names over snmp...
    Thanks in advance

    Hi, Ralf
    If not late
    I use script directly in monitoring system
    main ()
    VALUE=`snmpwalk -v 2c -c xxxCommunityxxx X.X.X.X 1.3.6.1.4.1.9.9.513.1.1.1.1.2 | wc -l`
    echo "Message: Warning! Number of registed APs decriased."
    echo "Data:Count"
    echo "Count\t$VALUE"
    exit 0
    main $*
    This is shell. but you can use simple only one line
    `snmpwalk -v 2c -c xxxCommunityxxx X.X.X.X 1.3.6.1.4.1.9.9.513.1.1.1.1.2 | wc -l`
    (from linux)

  • Hu is related to undershipment and count over ?

    Hi everyone ,
      Can anyone tell me how HU is related to undershipment and count over ?

    Did you try a reset? Hold down on the sleep and home buttons at the same time until the Apple logo appears on the screen, then let go of the buttons.

  • Counter over flow reading

    What is the utilization of counter over flow reading and annual estimate in counters? Is there any report or any application where it helps us in tracking?
    Regards,
    VM
    Edited by: V M on Jun 1, 2008 9:35 AM

    hi
    counter overflow reading is used wherein your counter reading overflows
    for example your milometer will only show 9999 miles ,once this counter has reached overflow  occurs ,i.e. the counter starts to count upwards from 0000 again
    Annual estimate is used for scheduling purpose for performance based scheduling and for multiple counter plan ,
    Multiple counter plan
    The system uses the current date as the start date and automatically calculates the planned dates based on the maintenance cycles, the scheduling parameters, the estimated annual performance and the last counter readings
    Performance based
    The system automatically calculates the planned date and call date based on the maintenance packages, the scheduling parameters, the estimated annual performance and the counter reading at the start of the cycle
    regards
    thyagarajan

  • Help! To design a counter for counting clocks

    Dear all,
    I want to design a counter that count all clocks of a square wave. I have tried but I am getting stuck somewhere. Here's attached the file that I started. In this project, my objective is to use NI-USB-6008 to send a square wave to an external oscilloscope. That square wave has to be self-controlled such that nth first clocks have  a certain frequency different to the next (n+1, .....,m) clocks. As part of that, I need to use a counter that I designed myself.
    Actually, I have the C++ codes for that:
    int count=0;
    if(result==1)
    count++;
    This is just the section that I want
    Attachments:
    DigOutFuncAuto.vi ‏180 KB

    Hello,
    I am a bit confused about your application, are you trying to count (input) clock edges or generate a clock signal with your 6008. If you want to count digital edges with the USB-6008 you can use the counter on the 6008 to count these edges; an example in the example finder exists already and can be found in the location shown below. If you want to generate this varying clock signal, it will be difficult with a USB-6008 since it software timed and updates to the digital line will depend on the updates over the USB bus. If you can clarify your application a bit, I may be able to make some suggestions.
    Eric
    Eric Liauw
    AE Specialist - Automated Test | CLD | CTD
    National Instruments

  • What is the difference between count(*) and count(1)

    what is the difference between count(*) and count(1)

    Hi,
    903830 wrote:
    some say count(1) is faster and some say count(*), i am confused about count function?In the link provided by Prakash :
    prakash wrote:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156159920245
    You can read :
    Followup   August 31, 2001 :
    I'll have to guess, since you don't say, that you are using 7.x and before when count(*) and count(1) were different (and count(1) was slower). In all releases of the databases for the last 4-5 years, they are the same.
    Don't waste your time on that.
    ;-)

  • Count(*) VS Count(ColumnName) VS Count(1)

    Can some explain which one is better,
    Count(*)
    Count(ColumnName)
    Count(1)
    I think they are same, any one has any other opinion.

    Count(*)
    Count(ColumnName)
    Count(1)
    The diference that's
    Count(*), check all table' columns of which can more slowly
    Count(ColumnName), Only count data of especificaded column, no check null fields
    Count(1), check only the table's column 1
    The use depends on the sitacion, and therefore the best performance, depends on the proper use.

  • Count(*) VS count(indexed_column_name)

    Hi, after a lot of reading here in the forum and the "ask tom" site, I can see that count(1) and count(*) are on the same, count(*) prove to be even faster sometimes. My question is: This is the same for indexed columns declared inside the count clause? Example:
    select count(*) from Person p, (lots of nasty joins from here...)
    VS
    select count(indexed_primary_key_person) from Person p, (lots of nasty joins from here...)
    From my reading, that could be more efficient in older oracle version (7 and before). What about today? Same speed? And is this information write in some FAQ or book?
    Thanks in advance,

    An indexed column can still contain NULLs, so the count vs count(*) may not be the same.
    SQL> create table t as select * from all_objects;
    Table created.
    SQL> create index t_idx on t (subobject_name);
    Index created.
    SQL> select count(*) from t;
                COUNT(*)
                   73045
    SQL> select count(subobject_name) from t;
    COUNT(SUBOBJECT_NAME)
                     2407Of course, this has nothing to do with indexes.
    A primary key column will give you the correct count. In fact, if you do an explain plan on 'select count(*) from t' where the table has a primary key, Oracle will probably get the count from the index and never touch the table.
    SQL> alter table t add constraint t_pk primary key (object_id);
    Table altered.
    SQL> explain plan for
      2  select count(*) from t;
    Explained.
    SQL> @xp
    | Id  | Operation             | Name | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |      |     1 |   112   (0)| 00:00:02 |
    |   1 |  SORT AGGREGATE       |      |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| T_PK | 76047 |   112   (0)| 00:00:02 |
    ----------------------------------------------------------------------

  • Count(*) Vs count(1)

    Hi
    Can some one tell me the difference between count(*) and count(1) in SQL
    I can see count(1) taking a lot of time compared to the other
    TIA

    Can some one tell me the difference between count(*)
    and count(1) in SQL
    I can see count(1) taking a lot of time compared to
    the other
    SQL is a language. There is no speed associated with it intrinsically.
    What database vendor are you using?
    And how are you timing it?
    And did you profile it?

  • Reset clock count/encoder counts

    Is there a way to programatically reset the clock count using labview? I am using an encoder and an e series DAQ board. When I am counting with the encoder, I come to a point where I would like to reset it to zero. I see that the examples all show that the count is reset after the loop is complete, but I would like to reset it during the loop to use it as a positioning tool. Reset to zero then start counting again from that point. Is this possible? Thanks.
    Using Labview 6.1 and MIO16E DAQ Board.

    Use the "Counter Control.vi" (Data Acquesition-> Counter->Advanced Counter). With the control code 1 you can resets the counter. Alternatively you may use the VI with control codes 4 and 2 which disarms and arms the counter again ("If you follow a disarm with another arm, then the acquisition restarts from the beginning"). That should do.

Maybe you are looking for

  • I-Photo crashes while creating a slide-show

    Hello, i have a big Problem with iPhoto. While creating the slide show and setting the time how long a Picture possible to see for each image, the program crashes. I have re-install the Program and install it new and check if i have the newest versio

  • Sale order - mtrl - prod ord ; table link

    hi, pl tell me a link through table and field - how to get a link between sale ord - item no. - mtrl - prodn ord no. - prodn posted qty. regards

  • How can I import scanned images into InDesign CS5 using Mac10.6?

    I want to be able to import scanned images. What file format must I save the data in?

  • Mavericks using too much ram ?

    Hy guys i have a doubt, in on macbook pro 17" late 2011 2.4ghz 16gbram ddr3 1600mhz, core i7 + ATI 1gb now im just with safari opened with 3 tabs and the memory clean show i have just 9.68ram avaiable, i read in another post a line command the i was

  • Synchronisation de mon ipad 2 et iphone 4s

    Bonjour, mon ipad et mon iphone se synchronisaient sans problème et voilà que cette semaine, je suis rendu compte d'un problème. En effet, plusieurs contacts et notes de mon iphone avaient disparus. Pourtant, ceux-ci sont encore présents sur mon ipad