Count the records

i have two tables like master and child having below records.Please find the records.
Master table
CODE STATUS
ABC U
ABC S
Histrory Table
CODE status
ABC S
I WANT THE RESULT
STATUS COUNT
U 1
S 2
i am using below query it is not working,It shows only for status(S) count 3 not for Status U.How shall we count this reocrd.,
SELECT x+y as total from
select count(1) x,staus from master
where code like 'AB%' group by status
select count(1) y,status from history
where code like 'AB%' GROUP BY STATUS)

Hello
You need to union all the two tables together:
tylerd@DEV2> CREATE TABLE dt_test_code_table
  2  (   col1    VARCHAR2(3),
  3      col2    VARCHAR2(1)
  4  )
  5  /
Table created.
Elapsed: 00:00:00.36
tylerd@DEV2> CREATE TABLE dt_test_code_table_hist
  2  (   col1    VARCHAR2(3),
  3      col2    VARCHAR2(1)
  4  )
  5  /
Table created.
Elapsed: 00:00:00.04
tylerd@DEV2>
tylerd@DEV2> INSERT INTO dt_test_code_table VALUES('ABC','U')
  2  /
1 row created.
Elapsed: 00:00:00.01
tylerd@DEV2> INSERT INTO dt_test_code_table VALUES('ABC','S')
  2  /
1 row created.
Elapsed: 00:00:00.00
tylerd@DEV2> INSERT INTO dt_test_code_table_hist VALUES('ABC','U')
  2  /
1 row created.
Elapsed: 00:00:00.00
tylerd@DEV2>
tylerd@DEV2> SELECT
  2      COUNT(*),
  3      col2
  4  FROM
  5      (   SELECT
  6              col2
  7          FROM
  8              dt_test_code_table
  9          UNION ALL
10          SELECT
11              col2
12          FROM
13              dt_test_code_table_hist
14      )
15  GROUP BY
16      col2
17  /
  COUNT(*) C
         2 U
         1 S
2 rows selected.
Elapsed: 00:00:00.03HTH
David
Message was edited by:
David Tyler
Eric beat me too it! :-)

Similar Messages

  • Count the Records in  an internal table without a loop.

    How do i count the number of records in an internal table without using the loop  statement.
    The Describe statement give the total no. of records in the internal table.But i want the count of the key fields in the internal table
    For eg
    Row Field
    1       A
    2       A
    3       A
    4       B
    5       B
    6       C
    Count of A = 3
    Count of B = 2
    Count of C = 1

    Dilip,
      I think isn't posible. Only 3 ideas:
    1ª, make other table "table2", similar to your actual table.
         table2[] = yourtable[].
         delete table2 where key <> 'A'.
         describe table table2 lines contA.
        But depending the amount of data, you may have problems in performance or memory consumption...
    2ª, make other table, only with the keys fields and a count field,
        data begin table2
           key_field1,
           cont type i.
        end data.
       when you append lines to yourdata, make a collect to this table:
        table2-keys = yourtable-keys.
        table2-cont = 1.
       collect table2.
       But only works if you can modify the program where data is appended, and you may be carefull when data is deleted :-(...
    3ª if your data if filled in a select, you may fill the table2 of point 2ª, making a similar select but:
       select keyfields count( * ) into table table2
      from ...
      where (the same you have to fill your original table...)
       group by keys.
    But you have the same problem is data is deleted later...
    I hope that any of the three is useful for you...
    Edited by: Diego Alvarez on Jan 5, 2010 5:09 PM

  • To count the records in the database table...

    I want to count the number of records in the database table (infotypes PA0000)
    is it possible to count ?
    Any function module is there?
    Thanks in advance..

    Hi dhavamani ponnusamy,
    SELECT COUNT(*) FROM <DB TABLE NAME> WHERE <CONDITION>.
    or
    SY-DBCNT Will have total no of records satisfying the given criteria in where clause.
    See below sample..
    Data: itab like mara occurs 0 with header line.
    Select * from mara into table mara.
    write:/ sy-dbcnt.
    Hope it will solve your problem...
    Reward points if useful..
    Thanks & Regards
    ilesh 24x7

  • A column that counts the records......need some help

    say i have a table with values {a, b, c, d, f};
    i want a column that counts the rows of these records with out putting the value manually.
    COL1 COL2
    0 a
    1 b
    2 c
    3 d
    4 f
    I have created a data block (wizard) for inserting the values into the table. But i want it to insert the values in COL1 automatically. Seems easy but i dont seem to be able to figure this out...

    with tab1 as
    (select 'a' col2 from dual
    union all
    select 'b' col2 from dual
    union all
    select 'c' col2 from dual
    union all
    select 'd' col2 from dual
    union all
    select 'f' col2 from dual
    -- End of test data
    select rownum - 1 col1, col2 from
    (select col2 from tab1 order by col2)
    COL1 COL2
    0 a
    1 b
    2 c
    3 d
    4 f Regards
    Dmytro

  • Count the record satisfied daily, weekly conditions

    Hi,
    I have a table which with the data being populated hourly (as below - with Date, Name, Value1, Value2 fields).
    I would need to query to get:
    1. Daily: Count the number of record which have Value1 <10 or Value2 >4 and occurs at least 3 times per day.
    2. Weekly: Count the number of record which satisfied the condition in "Daily" and happens 7 days consecutively for the past week.
    Thank you very much.
    Alex
    Table ABC               
    Date     Name Value1     Value2
    12/04/2010:01:00     TEST1     10     5
    12/04/2010:02:00     TEST1     10     4
    12/04/2010:03:00     TEST1     9     4
    12/04/2010:04:00     TEST1     9     4
    12/04/2010:05:00     TEST1     10     4
    18/04/2010:01:00     TEST1     10     4
    18/04/2010:02:00     TEST1     9     4
    18/04/2010:03:00     TEST1     9     3
    18/04/2010:04:00     TEST1     9     3
    Edited by: user8606416 on 16-Apr-2010 02:39

    We often help students ... but we insist that students help themselves too.
    The first thing you can do is read the FAQ and learn how to format listings with tags so we can read them.
    The second is that they try not just ask for a solution far more sophisticated than they could write themselves. I don't see evidence that you have tried to solve this yourself.
    BTW: DATE and NAME are reserved words in Oracle and should never be used to name anything.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • ALV Count the records in group

    I have a report which list the billing documents which sort and group by sales office. The layout is something like this
    Sales Office      Billing Document    Amount
    A                      0001                     1000
    A                      0002                     1000
    Doc. count = 2
    B                      0003                     1500 
    Doc. count = 1
    I know that I can add a column with the value 1 in each cell and sum them up.
    Is that any other alternatives?

    Hi,
    Where do you want to show this count. Do you want to show it as the column in output or in the header of the ALV. You can just see the entries in the output table and print that count.
    Reward points if useful.
    Regards,
    Atish

  • How to count the records?

    Hi,
    My data in the report is like below:
    INVOICE# DATE QTY
    ==============================
    111 07/03/03 1
    RT1 07/05/03 1
    222 07/08/03 2
    333 07/09/03 2
    RT2 07/10/03 1
    Is there any way that I can sum the QTY OF all the 'RT' invoice#?
    Thanks,
    Jun

    Hi
    Just put a Reports lavl summary column that sums the QTY column. You can have the summary column at the page and group level also.
    Thanks
    Rohit

  • How to return the record count of a query to a number variable

    How would I get the record count from a query without using a cursor to step through the query and count the records individually?
    query: select * from table1 where column1 = column2
    How would I get the record count of the query above?
    thanks,
    michelle

    I figured it out
    select count(*) into theCount
    from ( select * from table1 where column1=column2 );
    thanks,
    michelle

  • Need a relative sequence (count of record) in an input file in ESB input fi

    I am using ESB to pick up text files and pass them to a stored procedure. I have multiple variable length records in the file. I pass each record to the
    output file adapter, along with the input filename. I would also like to get a relative record number for each record within the file. I use an xsd file
    to convert the input to XML. The entire file is at the root level, each record is an element. Is there a way to get a relative count of each element?
    Here is the xsd file:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    targetNamespace="http://TargetNamespace.com/Filein"
    xmlns:tns="http://TargetNamespace.com/Filein"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified" nxsd:encoding="ASCII" nxsd:stream="chars" nxsd:version="NXSD">
    <xsd:element name="Root-Element">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="C1" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="C1" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;">
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    <!--NXSDWIZ:J:\\UPLD5383.INM:-->
    <!--USE-HEADER:false:-->
    I need to map the relative record number to a field in the output.
    Is there a function similar to the get filename that would return this value to me?
    <xsl:value-of select='ehdr:getRequestHeader("/fhdr:InboundFileHeaderType/fhdr:fileName","fhdr=http://xmlns.oracle.com/pcbpel/adapter/file/;")'/>
    I use this in the xsl file to get the file name .

    does each record start with a new line? if it does a
    simple wc -l can help you. If not, you can pre
    process this XML file by first removing all the new
    line characters using sed and then adding new line
    characters after the end tag of the xml using sed and
    finally doing a wc -l . this would be a simple shell
    script. Not sure if you want to use Unix shell
    scripting to achieve this.The sheer nature of XML means that it does not conform to any visual formatting. i.e. An xml file containing...
    <employee><empno>3</empno></employee>
    is identical in XML terms to...
    <employee>
    <empno>3</empno>
    </employee>
    which is also identical in XML terms to...
    <employee>
    <empno>
    3
    </empno>
    </employee>
    which is also identical in XML terms to...
    <employee><empno>
    3
    </empno></employee>
    etc.
    You cannot rely on the number of CR's or CR/LF's in the file to count the records. Proper XML processing should be used for such a task.

  • How can I get a count of records in a DB?

    If I want to get a count of the number of records in a table how do I do it?

    Generally, it's good practice to close the connection once you're done with it unless you have a reason to keep going back to it, in which case it probably becomes a performance issue. If you need to keep accessing the same connection repeatedly while your form is running (in Acrobat), I think you would be best to leave it open after initialization.<br /><br />You might consider placing the code which counts the records into a function inside a Script Object. This way, you can just call the Script Object method and retrieve the record count whenever you need it.<br /><br />Make sure you define the <b>oDB</b> variable outside the function but inside the Script Object:<br /><pre>var oDB = null;<br /><br />function GetRecordCount()<br />{<br />  if (oDB == null)<br />  {<br />    var sDataConnectionName = "<value>"; // example - var sDataConnectionName = "MyDataConnection"; <br /><br />    // Search for sourceSet node which matchs the DataConnection name <br />    var nIndex = 0; <br />    while(xfa.sourceSet.nodes.item(nIndex).name != sDataConnectionName) <br />    { <br />      nIndex++; <br />    } <br /><br />    var oDB = xfa.sourceSet.nodes.item(nIndex); <br />    oDB.open();<br />  }<br /><br />  oDB.first(); <br /><br />  // Search node with the class name "command" <br />  var nDBIndex = 0; <br />  while(oDB.nodes.item(nDBIndex).className != "command") <br />  { <br />    nDBIndex++; <br />  } <br /><br />  // Backup the original settings before assigning BOF and EOF to stay <br />  var sBOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("bofAction"); <br />  var sEOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("eofAction"); <br /><br />  oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayBOF", "bofAction"); <br />  oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayEOF", "eofAction"); <br /><br />  var itemCount = 0; <br /><br />  while(!oDB.isEOF()) <br />  { <br />    itemCount++; <br />    oDB.next(); <br />  } <br /><br />  // Restore the original settings <br />  oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sBOFBackup, "bofAction"); <br />  oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sEOFBackup, "eofAction"); <br /><br />  return itemCount;<br />}</pre><br />You can create a script object by right-clicking on the top-level form node ("form1" by default). Say you name your script object "Utils", you can then call the function inside of it from any event script like this:<br /><pre>this.rawValue = Utils.GetRecordCount();</pre><br />Stefan<br />Adobe Systems

  • How do I count the number of records returned in the CMIS query

    How do I count the number of records returned in the query CMIS?
    SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
    Euler Homero

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

  • How to know the count of record in CR XI?

    Post Author: Liu ming
    CA Forum: Deployment
    Hi All,
    I create a report by CR XI release 2. The report is viewed in ASP.Net. So, I would like show a message when the report have no record. My question is how to know the count of record?
    Thanks.

    I was able to do this by using
    ora:countNodes('Receive_1_Read_InputVariable','BILL','/ns2:BILL/ns2:CMS1500')

  • How to get the count of the records

    Hi all,
    how can we get the record count after the read statement.Means if we write a read statement based on a condition,then how can we know that how many records get effected for this read statement

    You can use loop statement to read the records and write in some internal table and after the end of the loop, you can use describe command to find the number of records.
    For eg. DESCRIBE TABLE tablename LINES lines.
    Here the "Lines" field will give the total number of records present in the table "tablename"

  • Applescript - how can I count the number of records in a Word data source?

    I have written a script in AppleScript to open Word and then perform a mail merge from a data source and everything is working fine.
    One thing I want to do but am struggling with is to return the number of records in the mail merge.
    I am trying things like:
    get last record of datasource of mydatasource
    and also haven't been able to find anything in the AppleScript 2004 Word Reference Guide.
    Can anyone help as I have been searching the web and trying things all day and I am sure it can't be difficult.
    Thank you.

    I don't think there is an automatic way to get a line count, but I don't have any problem just counting the lines on a page. Maybe some more information about what you are trying to do and why you can't do it would help someone to come up with a helpful suggestion.

  • What event should I use to grab the record count of a DataGrid?

    I have a "Go" button on a search form.  It works correctly, fetching records from a CF data service into a data bound DataGrid.  However, using the code shown below, the record count always shows zero.  I've tried putting the "..Provider.length" line shown below, into various events on the grid, so that it will always update the count at the correct time, but I get "null" object errors at run time. There seems to be no event that fires "AfterDataLoad".
                protected function btnGo_clickHandler(event:MouseEvent):void
                     getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                     tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;    //  This always returns zero.  Why?

    For example, this doesn't work.  The grid is told to loaded data on line 1, but this must just be only a message send to the Flash Player 10, because the processing doesn't stop and wait for the loading of data to complete, it just continues on to line 2, at which point '...Provider.length' is always zero the first time through.   So... the NEXT time the user clicks the Go button, line 2 is processed for the DataGrid which is holding data from the PREVIOUS search, so it updates the tabSbjs.label with the count from the previous search, not the current search.  The count of records is always for the previous data set.
                protected function btnGo_clickHandler(event:MouseEvent):void
    1               getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);  // edtSrch.text
    2               tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;                                                                            
    All I'm trying to do is (which seems like a very difficult thing to do in FB4):
    -Display a DataGrid popluated with data records
    -Display a count of how many records are in the data grid
    If I rely on CF9 functions, which can only return a single value, then I have to make two CF9  functions, with the exact same SQL, one that returns data, and one that returns a count of the records.... which is non-sensicle.
    There must be a simple way to do this, but I'm going around in circles.

Maybe you are looking for