Count total count (*)

Hello

I'm writing a select statement that returns the number of child records for each parent where the status of the parent record is 'I' (for non valid). referring to the following query:

Select PK_value,
Count (*) as CNT
of child_table C
where exists (select 'X' parent_table P
where P.status = 'I '.
and P.PK_value = C.PK_value
)
C.PK_value group
/

but I woud also like the total number of children records in the query above, is this possible?

I searched this forum and the web in general and not found an answer that works. Any help or advice would be appreciated!

Steve

Hi, Steve,.

You can do this by using GROUP BY ROLLUP .
Given that you do not post test versions of your tables, I will use CMII in the scott schema to illustrate.
To count is the number of employees in each Department and not located in Chicago, you can do this:

SELECT       CASE
          WHEN  GROUPING (e.deptno) = 0
          THEN  TO_CHAR (e.deptno)
          ELSE  '  Total'
       END               AS deptno
,       COUNT (*)          AS cnt
FROM       scott.emp   e
JOIN      scott.dept  d  ON  e.deptno     = d.deptno
WHERE     d.loc  != 'CHICAGO'
GROUP BY  ROLLUP (e.deptno)
ORDER BY  e.deptno
;

Output:

DEPTNO            CNT
---------- ----------
10                  3
20                  5
  Total             8

I hope that answers your question.
Otherwise, that, as others have said, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also to post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.

Published by: Frank Kulash on 12 March 2012 18:14
Example of change

Tags: Database

Similar Questions

  • Added a counter which keeps the total number of times where a loop has run, even if LabVIEW has been restarted.

    Hi all

    I am writing a VI to measure the data and insert into a database. The measures are controlled by a loop that runs once per minute. I want to give a unique to each measure identification number and store it too much in the database.

    To do this, I want to add a counter to this loop so that I can count the number of times that the loop is executed in total. It is, even if the VI, LabVIEW or even e PC is restarted, I want the counter to track the number of executions. If say the Edeka runs twice and then the VI is stopped and restarted, I want the number following on the counter to be three.

    Does anyone have an idea on how to do it? I'm gratefule for any help!

    Clara

    A suggestion. Can you write the last counter value in a txt file and read it all by running again the vi?

  • Function to count the total number of data channels

    I know that I had stumbled on a tiara function that returns the number of data in all of my data channels.  I can't seem to find the thread where I had seen it.  I'm looking to replace a script a long time user with this simple function in my future coding.

    Thank you!

    Hi CrshTstr,

    I actually still use GlobUsedChn for that.  In more recent versions of DIAdem, you can use commads as GroupChnCount() or Data.Root.ChannelGroups (1). Channels.Count to return the number of channels in a particular group.  But regardless of which group the channels are in the GlobUsedChn variable always returns the total number of channels currently on the data portal.

    Brad Turpin

    Tiara Product Support Engineer
    National Instruments

  • Script for counting both Yes and no in a column and returning the number of Yes on the Total

    (Acrobat Pro)

    I have 5 fields (DRDropdown1-5), who have 3 options (Y, N, NA). I only
    want to count the number of Y and N, then return the number of Y on the
    total of Y + N

    Any help is appreciated. I tell myself that if I see enough code, I'll get
    It is up.

    Thank you

    We are usually complete solutions, given a description or example of how to make the more difficult part, you should be able to take your knowledge of JavaScript and add the missing pieces. If you are not familiar with JavaScript, treat yourself and watch an introductory part (I like this for JavaScript in Acrobat: Beginning JavaScript for Adobe Acrobat ).

    Looking at your script, you already have most of the features in place. You should be able to edit the output (assuming that your domain may take a string and is not just a numeric field), by simply changing the last line:

    Change "event.value = total / total;" to the following:

    event.value = totalY + " of " + total;
    

    For easier reading, you can reformat the last two lines like this:

    if (total==0)
        event.value = "";
    else
        event.value = totalY + " of " + total;
    
  • report Total part count and the necessary sum

    Hello

    I have a requirement to report. I need to show subtotal as count and sum.

    example:

    Date total product_id

    November 7, 14 1 100

    2                       200

    Total count: 2 300

    November 6, 14 2 100

    3                         300

    4                          200

    Total count: 3 600

    Please suggest how to achieve

    Thanks in advance

    Product Id column-> change the formula-> rule of aggregation (total line)-> defined as County

    The Amount column-> change the formula-> rule of aggregation (total line)-> defined as the sum

  • A script that will count the total number of pages into multiple PDF files in a batch file?

    Is there a script I can use ExtendScript Toolkit that will count the total number of pages into multiple PDF files in a batch file?

    In another discussion I showed a JavaScript that you can use to write the number of pages to the console in a batch sequence. You would do exactly the same thing in Action, so the action would consist of a simple JavaScript (more tools > run JavaScript) which includes the code.

  • Automatically count the total number of steps

    I have a procedure with x steps. In the title manually type us the total number of steps. As you can understand this process often translates into a failure, where the number in the title does not match the actual number of steps.

    Is there a solution for automatically Indesign to count the steps below a certain style of paragraph and add the title number. I did find something similar.

    For example, where '5' in the title is automatically generated:

    How to count (5 steps)

    1. Be patient, start whispering 'a '.
    2. Then mentally count to two...
    3. ... three
    4. ... four
    5. Crying all of a sudden 'five' and pretend that nothing takes place.

    Thanks in advance

    This can be done very easily by the script. I wrote it while drinking my coffee in the morning.

    Front

    After

    I don't know what style names that you use so I used 'Header' and 'steps '. Change them to your style of the script name (in a text editor - Notepad for example, ESTK):

    If you add / remove certain steps, run the script again and it will update the numbers.

    Here is the script and here is an example document for the test.

    DISCLAIMER: I did not see your documents, so can't promise it will work for you, as it is.

    /* Copyright 2014, Kasyan Servetsky
    June 4, 2014
    Written by Kasyan Servetsky
    http://www.kasyan.ho.com.ua
    e-mail: [email protected] */
    //======================================================================================
    var scriptName = "Count number of steps - 1.1",
    doc;
    
    PreCheck();
    
    //===================================== FUNCTIONS ======================================
    function Main() {
        var foundItem, header, lastPar, num;
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = "(?s).+";
        app.findGrepPreferences.appliedParagraphStyle = "Steps";
        var foundItems = doc.findGrep(true);
        if (foundItems.length == 0) ErrorExit("Found nothing", true);
    
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            if (foundItem.paragraphs.length == 0) continue;
            header = foundItem.parentStory.paragraphs.previousItem(foundItem.paragraphs[0]);
            if (header.appliedParagraphStyle.name != "Header") continue;
            lastPar = foundItem.paragraphs[-1];
            num = lastPar.numberingResultNumber;
            if (num == -1) continue;
            InsertNum(header, num);
        }
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
    }
    //--------------------------------------------------------------------------------------------------------------------------------------------------------
    function InsertNum(header, num) {
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = "( \\()(\\d+)( Steps\\))$";
        app.changeGrepPreferences.changeTo = "$1" + num + "$3";
        app.findGrepPreferences.appliedParagraphStyle = "Header";
        var changed = header.changeGrep();
    
        if (changed.length == 0) {
            header.insertionPoints[-2].contents = " (" + num + " Steps)";
        }
    }
    //--------------------------------------------------------------------------------------------------------------------------------------------------------
    function PreCheck() {
        if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
        doc = app.activeDocument;
        if (!app.activeDocument.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
        Main();
    }
    //--------------------------------------------------------------------------------------------------------------------------------------------------------
    function ErrorExit(error, icon) {
        alert(error, scriptName, icon);
        exit();
    }
    //--------------------------------------------------------------------------------------------------------------------------------------------------------
    
  • When count sum ID number total &lt; 300

    Afternoon Folks,

    I was wondering if someone could help me with a query of code?

    I'm counting the number of Packs of Service where the total payment of the amount for each separate sp_id is less than 300 pounds and also more than 300 pounds.

    This is the code I have so far:

    Select the specialty
    count (distinct sp_id) "Service Packs",
    Sum (payment_total) "Total paid £»,
    round (sum (payment_total) / count (distinct sp_id), 0) 'average spend by MS.
    of a3_fact_sms_service_inv
    where specialized ("podiatry", "Podiatry")
    and service_date between '01 Jan 11' and 31 Dec 11'
    Specialty group

    This is the table that I want it to look

    SPECIALTY Service Packs Total paid £ average spend by SP * < 300 * > 300 *.
    Podiatry 129 25682,26 199 * 107 * 22 *.
    Podiatry 622 206651,08 332 * 403 * 219 *.

    I'm currently running application 10 g

    Concerning
    Farming :)

    First of all, ' 01 Jan 11' is not a date, but rather a string. Use literals date (or at least to_date):

    with t as (
               select  specialty,
                       sp_id,
                       sum(payment_total) sp_id_total
                 from  a3_fact_sms_service_inv
                 where specialty in ('Chiropody','Podiatry')
                   and service_date between date '2011-01-01' and date '2011-12-31'
                 group by specialty,
                          sp_id
              )
    select  specialty,
            count(sp_id) "Service Packs",
            sum(sp_id_total) "Total Paid £",
            round(sum(sp_id_total) / count(sp_id)) "Average Spend per SP",
            count(case when sp_id_total < 300 then 1 end) "Service Packs Less £300",
            count(case when sp_id_total = 300 then 1 end) "Service Packs Equal £300",
            count(case when sp_id_total > 300 then 1 end) "Service Packs Greater £300"
      from  t
      group by specialty
    /
    

    SY.

  • Count the total number of rows found in the schema

    Count the total number of lines present in the schema, including the table, sequence, view

    Desirable output

    Table sequence views
    20 of 1000 1000

    Do you mean that you need to count the number of Tables, views and sequence present in the schema?

    Hi something like that.

    SELECT a.view_cnt AS "View Count", b.tab_cnt AS "Table Count",
           c.seq_cnt AS "Sequence Count"
      FROM (SELECT COUNT (*) view_cnt
              FROM USER_VIEWS) a,
           (SELECT COUNT (*) tab_cnt
              FROM USER_TABLES) b,
           (SELECT COUNT (*) seq_cnt
              FROM USER_SEQUENCES) c
    

    Gives you,

    View Count      Table Count      Sequence Count
           153              878                   32
    

    Thank you
    Shankar

    Published by: Shankar Viji on August 28, 2012 03:03

  • Count the total number of specific words on each page

    I have a script that counts the number of times where the word 'Manager' is displayed on each page of a report.

    This is what is returned in the console after running the script:

    Count the number of managers 1 Page number 1

    Count the number of managers 2 Page number 1

    Count the number of managers 3 Page number 1

    Count the number of managers 4 Page number 1

    Count the number of managers 5 Page number 1

    Count the number of managers 1 Page number 2

    Count the number of managers 2 Page number 2

    Count the number of managers 3 Page number 2

    I need the console to report with only the total number of times that the word Manager appears on each page (once) and not iterate over each of them.

    Can someone please advise how this can be achieved?

    Script as follows:

    var this.numPages = NUMPAGES;

    for (var k = 0; k < numpages; k ++)
    {
    {
    numWords var = this.getPageNumWords (k);

    var number = 0;

    for (var i = 0; i < numWords; i ++)
    {
    var ckWord = this.getPageNthWord (k, i, true);
    var q = this.getPageNthWordQuads (k, i);
    Convert quads in the rotation by default user space
    Userspace used by links.
    m = (new Matrix2D).fromRotated(this,0);
    mInv = m.invert)
    r = mInv.transform (q)
    r = r.ToString)
    r = r.split(",");
    If (ckWord = "Manager")
    {
    Count ++;
    Console.println ("Count none managers" + count + "Number of Page" + (k + 1));
    }
    }
    }
    }

    Just move the statement outside the inner loop:

    var this.numPages = NUMPAGES;

    for (var k = 0; k)< numpages;="" k++)="">

    numWords var = this.getPageNumWords (k);

    var number = 0;

    for (var i = 0; i)< numwords;="" i++)="">

    var ckWord = this.getPageNthWord (k, i, true);

    var q = this.getPageNthWordQuads (k, i);

    If (ckWord = 'Manager') {}

    Count ++;

    }

    }

    Console.println ("Count none managers" + count + "Number of Page" + (k + 1));

    }

  • total count of rows in the vo.

    Dear all,

    I have an af:showDetailItem in which I have an af:table. I want to show the total number of records in the header of af: showDetailItem.
    example:
    Employees (count = 10)

    If someone has an idea how to fix this. ?


    Kind regards
    Sicard.

    Component              Version
    ================================================
    ADF Business Components         11.1.1.59.23
    Java(TM) Platform         1.6.0_21
    Oracle IDE              11.1.1.4.37.59.23
    Versioning Support         11.1.1.4.37.59.23

    You can use estimatedRowCount on the binding of the tree.
    Sample:

    
         
              .
              .
              .
         
    
    

    Jean Lou

  • OVERALL TOTAL incorrect (with COUNT DISTINCT)

    Hello

    I get incorrect results in a DISTINCT COUNT measure column GRAND TOTAL.

    I have 5 separate in Paris and 10 separate clients in New York, I want the grand total for the sum of the two, it is 15.
    But OBIEE calculates separate customers for all cities, so if there are customers in Paris and New York, the result is false.


    This is the result I get:

    City Number_Distinct_Customers
    ----------------------------------------------------------------------------
    Paris 5
    NEW YORK CITY 10
    GRAND TOTAL 12


    12 is the number of all separate clients.

    The correct GRANT TOTAL is expected to be 5 + 10 = 15



    Thank you
    Concerning

    I guess that COUNT(DISTINCT...) is regarded as the default aggregation in the Oracle replies.
    To come in this, change the State of aggregation of fx (formula column in the criteria of answers tab) to 'SUM '...

    Let me know if that solves your problem.
    -bifacts :-)
    http://www.obinotes.com

  • How to count the total number of records with distinction?

    Hello guys

    I have a report that contains a list of the types of company and other attributes as follows:
    Shipto               Company Type             GC Code               Measures
    A                         cc                             x                          100
                                                               y                          200
                                                               c                          120
    
    B                         YUT                         I                            200
                                cc                           U                           98
    
    G                         Maid                        rt                           200
                               YUT                        TT                         300
                               JTE                         TY                         400
    
                               
     
    The list goes on and... "Business type" appears is not the highest or the lowest... I would like to see what is the total number of different company types we have. By this report, there should be 5, but if I count or count (*) or rcompte, I actually get the total number of lines in the present report, which is not what I want...

    If someone could help me to find the total number of company types?

    Thanks in advance

    Have you tried this one?

    Sum (Count (distinct ColumnName))

  • Count (*) nested, giving me different results from those count (*) total

    Hello
    I use Oracle 10.2.0.4.0.


    Why these two statements return different counts?
    select booked.YEAR YEAR, booked.meaning "PRODUCT TEAM", count(booked.Total_Number_of_Booked_Orders) "Total Number of Booked Orders"
    from
    (
    select to_char(trunc(h.BOOKED_DATE),'YYYY') YEAR, scl.MEANING ,h.sales_channel_code PRODUCT_TEAM, count(*) Total_Number_of_Booked_Orders   
    from  
    oe_order_headers_all h, 
    oe_lookups scl
    where
    (h.CANCELLED_FLAG = 'N' or h.CANCELLED_FLAG is null)
    and h.sales_channel_code = scl.lookup_code      
    and scl.lookup_type = 'SALES_CHANNEL'
    and h.BOOKED_DATE is not null
    group by trunc(h.BOOKED_DATE), scl.MEANING, h.sales_channel_code
    ) booked
    group by booked.YEAR, booked.MEANING, booked.PRODUCT_TEAM
    order by booked.YEAR, booked.MEANING, booked.PRODUCT_TEAM
    and
    select booked.YEAR YEAR, booked.meaning "PRODUCT TEAM", count(*) "Total Number of Booked Orders"
    from
    (
    select to_char(trunc(h.BOOKED_DATE),'YYYY') YEAR, scl.MEANING, h.sales_channel_code PRODUCT_TEAM   
    from  
    oe_order_headers_all h, 
    oe_lookups scl
    where
    (h.CANCELLED_FLAG = 'N' or h.CANCELLED_FLAG is null)
    and h.sales_channel_code = scl.lookup_code      
    and scl.lookup_type = 'SALES_CHANNEL'
    and h.BOOKED_DATE is not null
    ) booked
    group by booked.YEAR, booked.MEANING, booked.PRODUCT_TEAM
    order by booked.YEAR, booked.MEANING, booked.PRODUCT_TEAM;
    I just took the "group of" inside and counted the full list on the outside. How is this different? One of them is probably fundamentally wrong. I can't just say why. Everyone? Maybe it's too early in the morning...

    user10382685 wrote:
    I just trying to get the total number of reserved command (e) by team and produced annually.

    Well this last query is by team and by the sense, by year, so as long as you want to the meaning as a group too, it should be ok.

  • How to get the total line count COUNT (*) SELECT and put on a page?

    Hello

    I use JDeveloper 10.1.3.4. I need get the total number of rows in a table and display it on a page and the problem in doing so. At the sqlplus prompt the row count simply would be, for example:
       select count(*) from BILL;
    I wonder if having this simple number must be so complicated and if there is more simple, better ways. Here's how I do it and the problem encountered.

    1. the name of the page to display the number is summary.jspx. It has a grain of support that "summed" as the managed bean name in faces - config.xml, and the name of the bean class is "summary." The component output on the page is:
    <h:outputText value="#{summary.totalStudentsCount}"
                  binding="#{summary.outputText5}" id="outputText5"/>
    2. in summary the bean code is:
        private Number totalStudentsCount;
        public static int NUMBER = Types.NUMERIC;
    
        public void setTotalStudentsCount(Number totalStudentsCount) {
            this.totalStudentsCount = totalStudentsCount;
        }
    
        public Number getTotalStudentsCount() {
            ZBLCModuleImpl zblcam = getZBLCModuleImpl();
            LoggedInStudentImpl studentTable = (LoggedInStudentImpl)zblcam.getLoggedInStudent();
            String sql = "select count(lsap_uid) from BILL";
            studentTable.setQuery(sql);
            return (Number)CallStoredFunction(NUMBER, "get_total_students(?)", new Object[] {});
        }
    
        private ZBLCModuleImpl getZBLCModuleImpl() {
            FacesContext fc = FacesContext.getCurrentInstance();
            ValueBinding vb = fc.getApplication().createValueBinding("#{data}");
            BindingContext bc = (BindingContext)vb.getValue(fc);
            DCDataControl dc = bc.findDataControl("ZBLCModuleDataControl");
            ApplicationModule am = (ApplicationModule)dc.getDataProvider();
            return (ZBLCModuleImpl)am;        
        }
    
        protected Object CallStoredFunction(int sqlReturnType, String stmt, Object[] bindVars) {
            CallableStatement st = null;
            ZBLCModuleImpl zblcam = getZBLCModuleImpl();
            try {
                st = zblcam.getDBTransaction().createCallableStatement("begin ? := " + stmt + "; end", 0);
                st.registerOutParameter(1, sqlReturnType);
                if (bindVars != null) {
                    for (int z = 0; z < bindVars.length; z++) {
                        st.setObject(z + 2, bindVars[z]);
                    }
                }
                st.executeUpdate();
                return st.getObject(1);
            }
            catch (SQLException e) {
                throw new JboException(e);
            }
            finally {
                if (st != null) {
                    try {
                        st.close();
                    }
                    catch (SQLException e) {
                        throw new JboException(e);
                    }
                }
            }
        }
    The idea of calling a stored function usnig as a "helper" method is 25.5.3 in the Developer's guide, which is closest to you in my need. It's for the functions with the one IN argument; but in my case, the function is not any argument IN. That's why, when you call the helper method CallStoredFunction(), I gave an empty as the last argument and amazing array that caused the problem:
    return (Number)CallStoredFunction(NUMBER, "get_total_students(?)", new Object[] {});
    3. the registered function has been tested and works fine at the sqlplus prompt:
    create or replace function get_total_students
       return NUMBER
    AS
       v_student_count NUMBER;
    BEGIN
       select count(ldap_uid)
       into v_student_count
       from bill;
       return v_student_count;
    END;
    4. when the summary.jspx page is run, the browser is full of error messages, the first long line is here (I have split several online for ease of reading):
    javax.faces.el.EvaluationException: 
      javax.faces.el.EvaluationException: 
        Error getting property 'totalStudentsCount' from bean of type 
        zblc.viewcontroller.backing.staff.Summary: oracle.jbo.JboException: 
          JBO-29000: Unexpected exception caught: 
            java.sql.SQLException, msg=Missing IN or OUT parameter at index:: 2
    Thus,.
    (1) what is the problem? What is this parameter IN or OUT of {color: red} index: 2 {color} consult? It has to do with the empty array as the last argument in the call to the helper method?
    (2) this approach is an overdose, and are there more simple and better ways?

    Thank you very much for help!


    Newman

    Hello

    Is there a specific reason why you don't simply create read only object to display with some count (*) as OFCASES from MYTABLE and then just drag and drop the attribute ofcases in page?

    Kind regards

    Branislav

Maybe you are looking for