How to sum the result from 2 different queries?

Hi ,
I would like to add the reslut of the below queries and insert into the status_count column of the temp table called edr_status_by_report_data.
How could I do that ?
SELECT         
          COUNT(status_code)
    FROM (SELECT site_id,
                 site_lane_id,
                (SELECT NVL(MAX(interval_start_date_time), date_time)
                   FROM edr_rpt_tmp_grouping_table
                  WHERE interval_start_date_time <= date_time) bin_start_date_time,
                        TO_NUMBER(TO_CHAR(date_time, 'hh24')) period,
                        vehicle_status  status_code
                   FROM edr_status_by_veh_data
                  WHERE vehicle_error_count = 0                         
                    AND vehicle_status > 0                   
         ) vehicles
SELECT         
          COUNT(status_code)
    FROM (SELECT site_id,
                 site_lane_id,
                (SELECT NVL(MAX(interval_start_date_time), date_time)
                   FROM edr_rpt_tmp_grouping_table
                  WHERE interval_start_date_time <= date_time) bin_start_date_time,
                        TO_NUMBER(TO_CHAR(date_time, 'hh24')) period,
                        vehicle_status  status_code
                   FROM edr_status_by_veh_data
                  WHERE vehicle_error_count = 0                         
                    AND vehicle_status = 0                   
         ) vehicles
      ;              

That just becomes:
SELECT count(*)
FROM   (SELECT site_id,
               site_lane_id,
               (SELECT NVL(MAX(interval_start_date_time), date_time)
                FROM   edr_rpt_tmp_grouping_table
                WHERE  interval_start_date_time <= date_time) bin_start_date_time,
               TO_NUMBER(TO_CHAR(date_time, 'hh24')) period,
               vehicle_status status_code
        FROM   edr_status_by_veh_data
        WHERE  vehicle_error_count = 0
        AND    vehicle_status >= 0);Or, if you needed to have both columns separately for some other purpose, you could still get them in one query:
SELECT COUNT(CASE WHEN status_code > 0 THEN 1) count_gt_zero,
       COUNT(CASE WHEN status_code = 0 THEN 1) count_zero,
       COUNT(CASE WHEN status_code > 0 THEN 1)
         + COUNT(CASE WHEN status_code = 0 THEN 1) total
FROM   (SELECT site_id,
               site_lane_id,
               (SELECT NVL(MAX(interval_start_date_time), date_time)
                FROM   edr_rpt_tmp_grouping_table
                WHERE  interval_start_date_time <= date_time) bin_start_date_time,
               TO_NUMBER(TO_CHAR(date_time, 'hh24')) period,
               vehicle_status status_code
        FROM   edr_status_by_veh_data
        WHERE  vehicle_error_count = 0
        AND    vehicle_status >= 0);

Similar Messages

  • How to export the result from executing sql statement to excel file ?

    HI all,
    Great with Oracle SQL Developer, but I have have a trouble as follwing :
    I want to export the result from executing sql statement to excel file . I do easily like that in TOAD ,
    anyone can help me to do that ? Thanks so much
    Sigmasvn

    Hello Sue,
    I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
    open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
    AddVMOption -Duser.language=en
    AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
    When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
    Regards
    Marcus

  • How to dispatch the result from test cases to the function that loads

    Hi ,
         I am currently working on writing a test case and i ant to execute the test case and the result of the test cases needs to be returned to function that loads the swf file using loader.
    Below is the structure
    1) Project A
             Has a action script file that has a loader which inturn loads the swf file.
    public function testRunner():void {
                loader = new Loader();
                loaderDispatcher = loader.contentLoaderInfo;         
                sharedEvents = loaderDispatcher.sharedEvents;
                parentURL = loaderDispatcher.loaderURL;
                parentDomain = URLUtil.getServerNameWithPort(parentURL);
                parentScheme = URLUtil.getProtocol(parentURL);
                load("http://localhost:8000/abc.swf");
        var callback:Function = addAsync(onMessage, 30000, {}, handleTimeout);
        sharedEvents.addEventListener("message", callback);
        /*Listener added to receive message event*/
        sharedEvents.addEventListener(MessageEvent.MESSAGE, onMessageEvent);
            private function load(location:String):void {
                // create SWF loader
                loaderDispatcher.addEventListener(Event.OPEN, onOpenEvent);
                loaderDispatcher.addEventListener(Event.INIT, onINIT);
                loaderDispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);
                loaderDispatcher.addEventListener(Event.COMPLETE, onComplete);
                loaderDispatcher.addEventListener(IOErrorEvent.IO_ERROR, onError);
                loaderDispatcher.addEventListener(Event.UNLOAD, onUnload);
                loaderDispatcher.addEventListener(Event.CLOSE, onClose);
                var request:URLRequest = new URLRequest(location);
        //request.idleTimeout = 8000;
        try{
    loader.load(request);
    _subMovie.addChild(loader);
           catch (error:Error)
                     trace("Unable to load URL: " + error);
                // listen for DISPATCH events
                sharedEvents = loader.contentLoaderInfo.sharedEvents;
        sharedEvents.addEventListener(DISPATCH_EVENT_TYPE, handleDispatch);
    2) Project B
          Project B has the test cases written and teh swf file for this project is abc.swf.
    test.mxml
    public function go():void {
    var core:FlexUnitCore = new FlexUnitCore();
    core.addListener(new TestCaseListener());
    core.run(ABCTest);
    var messageEvent:MessageEvent = new MessageEvent("message","action test","action testing");
    //loaderInfo.sharedEvents.dispatchEvent(messageEvent);
    When I load abc.swf file this inturn call the mxml file which runs the testcases by using the FlexUnitCore .
    What I am looking for is dispatching the result that is available in TestcaseListener to the call of loader ie; in Project A
    public class TestCaseListener extends RunListener  {
    public override function testRunFinished(result:Result):void {
    trace("testRunFinished invoked 1 ::");
    trace("failureCount::"+result.failureCount);
    trace("failures::"+result.failures);
    trace("successful::"+result.successful);
    Is there any way in which i can dispatch the result from testcaselistener to the call where this swf file is loaded .

    Hello Sue,
    I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
    open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
    AddVMOption -Duser.language=en
    AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
    When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
    Regards
    Marcus

  • How to sum the  result rows at query designer

    Hi,
    We want to sum  the result rows which are at the end of the row by the help of query designer?So ,we directly see at analyzer
    exp:
       ..A.jan...A.feb...B.may...B.jun...SumA...SumB....SumA+B
    X..1............9..........6..............7........10.........13..........?????
    Edited by: zarata on Oct 23, 2011 12:49 PM
    Edited by: zarata on Oct 23, 2011 1:07 PM

    Hi,
    Could you please provide some more information.
    if you have characteristics iobject whose values are (A, B etc) and calendar month in rows and then at column level you have key figures then if you have turn on the "Display Result Rows" property of both iobject in Bex  as "Always" you can get the result. At the same time you can set "Display Overall result" property of the Query to get overall result.
    Regards,
    Pravin

  • How to join the results from 2 webservices using BPEL?Architecture question

    Hi,
    I am new to BPEL. BPEL process calls two webservices, which return complex results. I need to process the results from 2 webservices using BPEL .The result will be a complex xml, join/merge of previous results.
    What is the best practice to do it with BPEL?
    I see three ways:
    1.To do the processing (join/ merge) inside the BPEL process itself and return complex xml.
    2.Develop auxiliary webservice in java. Auxiliary webservice will do the processing (join/merge). Call this webservice from BPEL process.
    3.Do a plain concatenation of the two XMLs in BPEL and forward it to the frontend. Frontend then will do all the logic on its side
    Thanks,
    Boris

    you could process the XMLs one at a time, and use XSL transformations to process the payload to a target schema.
    Activity 1:
    output from webservice1 -> transform 1 -> partial XML (of target schema)
    Activity 2:
    output from webservice2 -> transform 2 -> completed XML (of target schema)
    Regards,
    Shanmu.

  • How to tokenize the result from a query

    Hi,
    I need some help in writing a query or stored procedure for the following scenario
    select rname from emp where username='user200';
    This query will return the result,as comma separated,in the format r100,r101,r102
    Now,I have to write another query using the above result like below
    select place from loc where rname in ('r100','r101','r102');
    Basically,I need to break the string 'r100,r101,r102' into 3 tokens.Can someone help me write a stored procedure or query for this?
    Thanks
    Ravi.

    Ravi, Try this.
    CREATE OR REPLACE procedure str_token
    is
    input_buffer varchar2(100);
    var1 varchar2(10);
    var2 varchar2(10);
    var3 varchar2(10);
    n1 number(4);
    n2 number(4);
    n3 number(4);
    cursor c1 is
    select place from loc1 where rname in (var1,var2,var3);
    begin
    select rname into input_buffer from emp1 where username='user200';
    n1 := instr(input_buffer,',',1,1);
    n2 := instr(input_buffer,',',1,2);
    n3 := length(input_buffer) + 1 ;
    select
    substr(input_buffer,1,n1-1),
    substr(input_buffer,n1+1,n2-n1-1),
    substr(input_buffer,n2+1,n3-n2-1)
    into var1, var2, var3
    from dual;
    for i in c1
    loop
    dbms_output.put_line('place:'||i.place);
    end loop;
    end;
    Regs,
    Karthik

  • How to use the result from a taglib?

    Hi people.
    I've been looking arround for some feedback on how to use the output generated by a taglib on jsp code but I haven't been able to find any.
    Could somebody tell me how to do that please?

    It works something like this:
    The tab library consists of a class library and a tag libraray descriptor file. In your jsp header you include a taglib directive which associated athe TLD with a particular name prefix. Then you can include XML tags with that prefix and the tag library class to which they are connected will be invoked from the servlet that is generated from the JSP. This tag code can do pretty much anything, but usually what it mostly does is write HTML to the response stream. Opening tags and closing tags can both add whatever text they like to the stream which is sent to the client.
    So including the tag in you JSP will usually suffice to cause generated output, it's up to the taglib.

  • How to get the result from graph  based on table prompt?

    I have one report in which I am having one table and three Graphs. I have added table prompt for one column i.e department. In that I have given three values. The values of my table changes as per the table prompt. But my requirement is my graphs should show me the result as per the selection of departments in table prompt. Please give me the solution for the same.

    Hi,
    Create a event channel the table view and refer the same channel name in the graph properties.
    Edit Graph --> Edit properties --> Enable Master-Details Events --> Give the channel name.
    It will work for the selection of table .
    Mark if helps.
    Raja Mohamed

  • How to processing the results from the select statement in SQL query?

    Hi
    This might be too simple, but my knowledge of the SQL is very limited...
    I have table where I do have details from calls (Lync QoE).
    I can take all calls from the table, but I would like to count the concurrent calls on the table. This is how I got it work on the Excel to work (but I would like to do that on the SQL statement to get it more dynamic use):
    Table have these line and this is what I get out from the Select):
    [callid],[start],[end]
    1ABC,1.1.2014 01:00:15, 1.1.2014 01:01:00
    5DEF,1.1.2014 01:00:45, 1.1.2014 01:05:00
    FDE2,1.1.2014 01:03:15, 1.1.2014 01:04:00
    KDJ8,1.1.2014 01:04:15, 1.1.2014 01:06:00
    FDJ8,2.1.2014 01:04:15, 2.1.2014 01:06:00
    KDSE,3.1.2014 01:04:15, 3.1.2014 01:06:00
    The information I would like to get, is what is the maximum amount of the concurrent calls per day.
    On the excel I basically count line by line how many concurrent calls each line have had, and then pickup the highest one. On above example the calls 5DEF, FDE2 and FDE2 have been active at the same time which gives 3 for the first day.
    The table is ordered by the start. So let say the code is on the third line (FDE2). I need to count calls from before which end time is after the start time (of FDE2), but also I need to count calls after (FDE2) which are started before the current
    call has ended.
    Petri

    Unfortunately your post is off topic as it's not specific to SQL Server Samples and Community Projects.  
    This is a standard response I’ve written in advance to help the many people who post their question in this forum in error, but please don’t ignore it.  The links I provide below will help you determine the right forum to ask your question in.
    For technical issues with Microsoft products that you would run into as an end user, please visit the Microsoft Answers forum ( http://answers.microsoft.com ) which has sections for Windows, Hotmail,
    Office, IE, and other products.
    For Technical issues with Microsoft products that you might have as an IT professional (like technical installation issues, or other IT issues), please head to the TechNet Discussion forums at http://social.technet.microsoft.com/forums/en-us, and
    search for your product name.
    For issues with products you might have as a Developer (like how to talk to APIs, what version of software do what, or other developer issues), please head to the MSDN discussion forums at http://social.msdn.microsoft.com/forums/en-us, and
    search for your product or issue.
    If you’re asking a question particularly about one of the Microsoft Dynamics products, a great place to start is here: http://community.dynamics.com/
    If you think your issue is related to SQL Server Samples and Community Projects and I've flagged it as Off-topic, I apologise.  Please repost your question and include as much detail as possible about your problem so that someone can assist you further. 
    If you really have no idea where to post your question please visit the Where is the forum for…? forum http://social.msdn.microsoft.com/forums/en-us/whatforum/
    When you see answers and helpful posts, please click Vote As Helpful,
    Propose As Answer, and/or Mark As Answer
    Jeff Wharton
    MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt), MCT, MCPD, MCSD, MCSA, MCITP, MCDBA
    Blog: Mr. Wharty's Ramblings
    Twitter: @Mr_Wharty
    MC ID:
    Microsoft Transcript

  • How to join the result from one autocomplete textbox to many textboxes

    Hi,
    I have one textbox which run as autocomplete from SQL database as i write the customer name so i get all his information(such: phone, address, email, ...), And this file connected with master page. Now i want to get each record (phone, address, email, ...)
    data from this autocomplete textbox to many textboxs. What i can do?

    Hello,
    What you can't do is work off normal methods such as TextChanged as these events will not work simply because when AutoComplete is utilized TextChanged will fire twice, once for user enter data, once for suggestions. You could have the user press ENTER and
    get the text in the TextBox via KeyDown event of the TextBox. I have an example in
    the following article.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Af:query - How to get the result rowsets

    Hi,
    I have a requirement where i need to search the db rows on and append the results the adf rich table on each search.
    For this i am using af:query component. And trying to get the result rows for the named criteria.
    String mexpr = "#{bindings.DestinDescVOCriteriaQuery.processQuery}";
    processMethodExpression(mexpr, queryEvent, QueryEvent.class);
    ViewCriteriaManager vcm = getDestinDescViewObj().getViewCriteriaManager();
    ViewCriteria vc = vcm.getViewCriteria("DestinDescVOCriteria");
    getDestinDescViewObj().applyViewCriteria(vc);
    AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
    adfFacesContext.addPartialTarget(tblDestinDesc);
    However on each click of search the rows searched in the previous attempt are not retained.
    Can anyone let me know how to get the result from named criteria and append it the table?
    Thanks
    Ajay

    Can anyone help?

  • How to get the results for given Bind Variable

    Hi
    Can any one help me how to get the result rows from the View Object after executing the view object query by setting bind variable?
    snippet as follows
    viewObject.setNamedWherClauseParams("name","hei");
    viewObject.executeQuery();
    How to get the results from viewObject is my question..?
    Thanks in advance

    Should be something like
    while (vo.hasNext()){
    Row r = vo.next();
    r.getAttribute....
    You might want to read the "most commonly used methods" appendix in the ADF Developer Guide.

  • How to sum the count results?

    Hi,
    I have this query:
    SELECT SUM (cnt) FROM
    select max(timestamp), min(timestamp), count(1) as cnt from table1
    union
    select max(timestamp2), min(timestamp2), count(1) from table2
    It display sum of all count results. But how to display each result from query and sum result at the end?
    Best.

    OK, thanks, that helps a lot. Though if you could put {noformat}{noformat} before and after your code snippets that would help further.
    So you basically want a total at the end:WITH test_data AS (
    SELECT 1 col1, TO_DATE('16-AUG-08', 'DD-MON-YY') max_ts, TO_DATE('16-AUG-08', 'DD-MON-YY') min_ts, 1000 cnt FROM DUAL UNION ALL
    SELECT 1, TO_DATE('31-OCT-08', 'DD-MON-YY'), TO_DATE('31-OCT-08', 'DD-MON-YY'), 1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('10-FEB-09', 'DD-MON-YY'), TO_DATE('01-JAN-01', 'DD-MON-YY'),422 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('20-FEB-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('20-FEB-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),14825 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-FEB-09', 'DD-MON-YY'), TO_DATE('27-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('28-FEB-09', 'DD-MON-YY'), TO_DATE('26-FEB-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('01-MAR-09', 'DD-MON-YY'), TO_DATE('01-MAR-09', 'DD-MON-YY'),1000 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('05-MAR-09', 'DD-MON-YY'), TO_DATE('16-AUG-08', 'DD-MON-YY'), 5150 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-APR-09', 'DD-MON-YY'), TO_DATE('30-OCT-08', 'DD-MON-YY'),8733 FROM DUAL UNION ALL
    SELECT 1, TO_DATE('27-APR-09', 'DD-MON-YY'), TO_DATE('20-FEB-09', 'DD-MON-YY'),10000 FROM DUAL)
    -- end test data
    SELECT col1, max_ts, min_ts, sum(cnt) total_cnt
    FROM test_data
    GROUP BY ROLLUP((col1, max_ts, min_ts));
    1 16-AUG-08 16-AUG-08 1000
    1 31-OCT-08 31-OCT-08 1000
    1 10-FEB-09 01-JAN-01 422
    1 20-FEB-09 20-FEB-09 15825
    1 27-FEB-09 27-FEB-09 1000
    1 28-FEB-09 26-FEB-09 1000
    1 01-MAR-09 01-MAR-09 1000
    1 05-MAR-09 16-AUG-08 5150
    1 27-APR-09 30-OCT-08 8733
    1 27-APR-09 20-FEB-09 10000
    45130
    11 rows selected.

  • How can i import tables from a different schema into the existing relational model... to add these tables in the existing model? plss help

    how can i import tables from a different schema into the existing relational model... to add these tables in the existing relational/logical model? plss help
    note; I already have the relational/logical model ready from one schema... and I need to add few more tables to this relational/logical model
    can I import the same way as I did previously??
    but even if I do the same how can I add it in the model?? as the logical model has already been engineered..
    please help ...
    thanks

    Hi,
    Before you start, you should probably take a backup copy of your design (the .dmd file and associated folder), in case the update does not work out as you had hoped.
    You need to use Import > Data Dictionary again, to start the Data Dictionary Import Wizard.
    In step 1 use a suitable database connection that can access the relevant table definitions.
    In step 2 select the schema (or schemas) to import.  The "Import to" field in the lower left part of the main panel allows you to select which existing Relational Model to import into (or to specify that a new Relational Model is to be created).
    In step 3 select the tables to import.  (Note that if there are an Foreign Key constraints between the new tables and any tables you had previously imported, you should also include the previous tables, otherwise the Foreign Key constraints will not be imported.)
    After the import itself has completed, the "Compare Models" dialog is displayed.  This shows the differences between the model being imported and the previous state of the model, and allows you to select which changes are to be applied.
    Just selecting the Merge button should apply all the additions and changes in the new import.
    Having updated your Relational Model, you can then update your Logical Model.  To do this you repeat the "Engineer to Logical Model".  This displays the "Engineer to Logical Model" dialog, which shows the changes which will be applied to the Logical Model, and allows you to select which changes are to be applied.
    Just selecting the Engineer button should apply all the additions and changes.
    I hope this helps you achieve what you want.
    David

  • HT4061 How do I consolidate purchases from two different ids that are on the same bank account, and eliminate the extra id without losing any purchases?

    How do I consolidate purchases from two different ids that are on the same bank account, and eliminate the extra id without losing any purchases? I want my music to match on both ipad and computer.

    Purchases are forever tied to the AppleID they were bought with. There is currently no way to consolidate AppleIDs. Sorry.

Maybe you are looking for

  • JDBC Receiver does not convert empty string to NULL

    Hello experts, I am facing a problem with an INSERT statement to ORACLE DB where some of the fields are empty, for example: - <STATEMENT_VLP_CONT_DETAILS> - <TABLE_VLP_CONT_DETAILS ACTION="INSERT">   <TABLE>VLP_CONT_DETAILS</TABLE> - <ACCESS>   <VLP_

  • Library - Documents displayed in wrong folder

    Hi all Another strange case: In a document libarary I have 50 folders. Each of them contain 2-3 documents. My view shows 30 elements per page. When I go to the next page to view the folders 31-50 everything seems to be OK. But when I go back to the f

  • 2 ISP link failover in ASA 5505

    Hi, I have ASA 5505, want to configure the 2 ISP link Tata and Airtel with failover. I want to configure the WebVPN with failover, so that user don't need to change the public address when one link goes down. thanks with regards Ashish Kumar

  • How to delet the DNL_CUST_PROD1

    Hi, I have down the initial download of DNL_CUST_PROD1 only the following things have been downloaded R3MATCLASS and R3PRODSTYP but actually i have to download the R3MATCLASS,R3PRODHIER and R3PRODSTYP. When i do the initial download once again it is

  • How to avoid multiple selection in ALV tree control?

    Hi, Experts, I want to avoid multiple selections on Alv tree control after pressing control keyboard button(Ctrl). Even by pressing Ctrl keyword button i want to select only one row of a Alv tree control.i have used cl_salv_tree class for it is there