How to get count and other field in one select

Hi,
I am try to get total rows and some fields in two separate select:
1. select count(id) into totalRows from mytable m where m.cat = 'CSV'
2. select m.id, m.cat, m.updateTime from mytable m where m.cat = 'CSV'
(all rows in mytable are distinct base on id field)
How can I combine them into one query to make it faster so that no need to compare the m.cat field twice?
Thanks.
David

Here's one solution :
SQL> desc test;
Name Null? Type
ID NUMBER
CAT VARCHAR2(10)
UPDATE_TIME TIMESTAMP(6)
SQL> select * from test;
ID CAT UPDATE_TIME
1 XYZ 09-JAN-04 09.04.17.000000 AM
2 CSV 09-JAN-04 09.04.31.000000 AM
4 ABCD 09-JAN-04 09.04.41.000000 AM
5 CSV 09-JAN-04 09.04.53.000000 AM
6 ABC 09-JAN-04 09.05.00.000000 AM
7 CSV 09-JAN-04 09.05.06.000000 AM
8 GGG 09-JAN-04 09.05.17.000000 AM
7 rows selected.
SQL> select id, cat, update_time
2 ,Count(*) Over (Order By cat) As TotCnt
3 from test
4 Where cat = 'CSV'
5 /
ID CAT UPDATE_TIME TOTCNT
2 CSV 09-JAN-04 09.04.31.000000 AM 3
5 CSV 09-JAN-04 09.04.53.000000 AM 3
7 CSV 09-JAN-04 09.05.06.000000 AM 3
SQL>
-- Shailender Mehta -

Similar Messages

  • How to get tools and other bars back in view after deleting show-bar?

    How to get tools and other bars back in view after deleting show-bar?

    Hello Jouko.
    You can go into View > Toolbars and select the ones you want to see. If you can't see the menu bar you can simply tab ALT on your keyboard (I think F10 works too) to show it.

  • Count and Other fields - VBAK

    Hi All,
    I want to find the count the no of Orders from VBAK for a combination of VBTYP and AUART.
    Select Count(*) from vbak into table t_vbak where vbeln in s_vbeln
                                                                  and    vkorg eq p_vkorg
                                                                  group by vbtyp  auart.
    This will only give the count.
    I also need other data like erdat ernam and a bunch of other fields for this combination.
    Do I need to select again from VBAK??
    Any ideas.
    Meghna

    Hi Meghna,
    The statement you written above, Is it correct, Is it working,,,
    I will not work as in count(*)  it will not allow to select the data into a table and instead you need to write like this.
    DATA : i_vbak type i.
    Select Count(*) from vbak into i_vbak where vbeln in s_vbeln
    Then you will get the no. of records,,,
    It give No difference again to count Erdat or Ernam...! As it will be the same count.
    If you need the Maximum then it will give you ethe maximum date but for time it give maximum time in 24 Hours but it may be different from the latest date time....
    lets say you ha two record in April & May,, May you created time at 1 PM.. In April you created at 3 PM..
    for max time,,,, you will get April,
    And for max date you will get May,,,
    remember that.
    Count is for No. of records,,, & Max is for maximum no. or date or version,,,
    Thanks & regards,
    Dileep .C

  • How to get telephone and mobile phone for one partner

    Hello Expert,
    In VA03, I open one sales order and go into the partner tab. Then I selection one partner and click "Detail" button, one page with partner detailed information will pop up.
    In the pop-up window:
    There are two fields: Telephone and Mobile Phone.
    In my program, I want to get these two information. 
    I tried to call FM 'ADDR_COMM_GET' by passing address_number(VBPA-ADRNR), table_type('ADTEL'), iv_current_state(SPACE). For some partner, it works, but for others it doesn't work.
    Then I find table ADR2 which is used to keep phone infomration. There are two entries in the table. But how can I identity which one is telephone and which one is Mobile phone?
    So can any expert help me on how to get the telephone and Mobile Phone of the pop-up page?
    Thanks in advance,
    Best Regards, Johnny.

    Read ADR2-TEL_NUMBER where ADDRNUMBER = VBPA-ADRNR and R3_USER = '2' or '3'.
    These are the possible values
            Telephone is Landline Telephone
    1     Telephone is Default Under Landline Telephones
    2     Telephone is Mobile Telephone but Not Default Mobile Phone
    3     Telephone is Default Mobile Telephone
    X     Obsolete - No Longer Valid

  • How to get ID and others of BP while creating BP relations.

    Hi all,
    When we create relations to the partner, we want to get the value of ID and the others BUT000 of BP from the buffer before save.
    But, an error occurs when I carry out FM BUP_MEMORY_BUT000_GET in BADI BUPA_RELATSHP_UPDATE.
    How can I get the value of BUT000 handling now from a buffer?
    Please, teach us the solution!
    Regards,
    miururu

    Hi,
    If you are creating a relation these informations that you need is assigned to the table that is a parameter in this badi.
    Best regards,
    Caíque Escaler

  • How to get WIDTH and HEIGHT fields from applet tag?

    I am developing an applet using JDK1.1 (to ensure microsoft jvm compatability).
    A problem I'm facing is that there are no getWidth() or getHeight() method for Applet in 1.1, so I am hoping I can get this info from my html: <APPLET CODE="MyApplet" WIDTH=600 HEIGHT=856></APPLET>
    getParameter didn't work, so does anyone have any ideas how I could get the width and height?
    Cheers,
    James

    Write a jpeg decoder that can figure out how to determine the width/height of a jpeg file? Google it.
    Or if you're really lazy, load each jpeg using the
    Toolkit.loadImage( URL ) function and use getWidth/getHeight from there, but that's slow.

  • How to get SapScript and Smartform printed in one spool request?

    Hello experts,
    I want to print the production order package in one spool request.
    Print program consists of Smartform and SapScript.
    First page is in landscape format with barcode(Smartform) and the rest is in portrait format(Sapscript).
    In SAP documentation is written that it is possible for several Smartforms to be printed in one spool request.
    Is it possible for 1 Smartform and 1 SapScript called from a single program to be printed in one spool request?
    I have tested it with calling first the Smartform control-no_close= 'X' without success.
    Can anyone tell me if this is possible and how?
    Thank you.
    Kind regards,
    Danijela

    Hi
    In the driver program .
    *"Selection screen elements............................................
    SELECTION-SCREEN BEGIN OF BLOCK block  WITH FRAME.
    PARAMETERS:
    p_script   RADIOBUTTON GROUP rad1,
    p_smartform RADIOBUTTON GROUP rad1,
    SELECTION-SCREEN END OF BLOCK block.
    *"Selection screen elements............................................
    SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
    PARAMETERS:
    p_single RADIOBUTTON GROUP rad2,      " All the spool request
    p_ind    RADIOBUTTON GROUP rad2.
    SELECTION-SCREEN END OF BLOCK block1. " Single spool request
    If p_script EQ 'x'.
    w_form = 'Y_SCRIPT'.
      Elseif p_smartfom EQ 'X'.
       w_form = 'Y_SMARTFORM'.
    ENDIF.
    call function 'SSF_FUNCTION_MODULE_NAME'.
    Call function 'SSFCOMP_OPEN'.
    w_control-no_open   = ' '.
        w_control-no_close  = ' '.
    *"Single spool request..................................................
        IF p_single EQ 'X'.
          w_control-no_open   = 'X'.
          w_control-no_close  = 'X'.
        ELSE.
    *"Individual spool request.............................................
          IF w_flag NE '1'.
            w_control-no_open  = 'X'.
            w_control-no_close = ' '.
            w_flag = 1.
    CALL FUNCTION '    '-----> smartform function module.
    CALL FUNCTION 'SSFCOMP_CLOSE'.
    Regards,
    Sravanthi

  • How to get count,index and compare to arraylists

    hi
    how to get count,index and comparing of 2 arraylist.... plz suggest me asap...

    How is your question related to JDBC? And what have you done so far with your code?

  • How to get total of any field in sapscript?

    Hello ,
    i m making sapscript...
    How to get total of any field in sapscript?

    Hi
    Yes, you can define a variabe in your print program and pass it to the SAPScript.
    LIKE:
    Define L_SUM in the Global data.
    DATA: L_SUM TYPE BSEG-DMBTR.
    LOOP AT ITAB.
    L_SUM = L_SUM + ITAB-AMOUNT.
    ENDLOOP.
    CALL FUNCTION 'WRITE_FORM'
    WINDOW = 'MAIN'
    ELEMENT = 'TOTAL'.
    Now, in your SAPScript, create a text element in MAIN window
    /E TOTAL
    Total,, &L_SUM&.
    Go through below link
    http://sap-img.com/sapscripts/sapscript-how-to-calculate-totals-and-subtotals.htm
    Regards,
    Chandru

  • How to get count of rows for a table?

    Hi,
    How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
    Regards,
    Devashish

    Hi Devashish,
    WdContext.node<Your_node_name>().size() will give you the no: of rows.
    This should be the node that is bound to the table's datasource property.
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
    You can access an attribute of a particular row as
    WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
    Hope this helps,
    Best Regards,
    Nibu.
    Message was edited by: Nibu Wilson

  • How to get the object class field value in CDHDR table for vendor

    hi
    how to get the object class field value in CDHDR table for vendor

    Try KRED/KRED_N as object class in CDHDR for Vendor.

  • How to get gui_download and gui_upload with popup filename?

    how to get gui_download and gui_upload with popup filename?

    Here is a short example.
    report zrich_0003 .
    data: ifiletab type filetable.
    data: xfiletab like line of ifiletab.
    data: xstring type string.
    data: rc type i.
    data: itab type table of string.
    data: xtab type string.
    start-of-selection.
      call method cl_gui_frontend_services=>file_open_dialog
        changing
          file_table              = ifiletab
          rc                      = rc.
      read table ifiletab into xfiletab index 1.
      xstring = xfiletab-filename.
      check not xstring is initial.
      call method cl_gui_frontend_services=>gui_upload
        exporting
          filename                = xstring
      changing
        data_tab                = itab.
      loop at itab into xtab.
        write:/ xtab.
      endloop.
    Regards,
    Rich Heilman

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • How to get vendor and company code based on logistic invoice document

    how to get vendor and company code based on logistic invoice document in abap/4?

    Hello Kumar
    When you call BAPI_INCOMINGINVOICE_GETDETAIL using
    INVOICENUMBER = <number of invoice>
    FISCALYEAR = <fiscal year>
    the returned HEADERDATA contains what you are looking for:
    HEADERDATA-COMP_CODE
    HEADERDATA-DIFF_INF
    Regards
      Uwe

  • How to get max and min salary in a table

    How to get max and min salary in a table

    SQL> select max(sal),min(sal) from emp;
      MAX(SAL)   MIN(SAL)
          5512        800
    SQL>

Maybe you are looking for

  • Using i-prefix in an app name

    Hello, 1- Can I use i-Prefix in an app name like in iGame or iSaw? 2- Is it allowed to put an unknown coach's name in the app "Mr. John's Tips"?

  • Need help with enhanced data source in Production system

    Hello Gurus, 1.                  I enhanced a datasource in BW and populated the field using customer exit using CMOD function. In Dev system, i dont have much data, so I deleted the whole data and did full load. what shud I do in Production side, so

  • LSMW Source and Field Mapping

    Hi,   I'm trying to use the LSMW.  What is the fastest way to maintain the source field and relationship?? Is it possible to define the source field and length in a text file and load it in the LSMW?? Regards, Kit

  • HW Inventory trouble

    The following is with SCCM 2012R2 CU3 I have been adding a few Hardware Inventory classifications.  Mostly, they work correctly but sometimes they don’t work quite right. Usually, the inventory shows up in Resource Explorer correctly, but other times

  • How to start a systemd with certain configuration options?

    Hello, I do not understand what wiki page at arch that can help me to understand how I can start a daemon with certain configuration options. I know I can start with # systemctl enable unit , but for example, if I whanted to start "xboxdrv" with the