Simple query to find the difference between 2 numbers in one column to another column

Hello

I would like to know the difference between 2 numbers in same column corresponding to a condition of another column. How do that?

For example: say I have a table with 3 columns A, B and C.

A > Varchar2

B > Varchar2

C > number

A B C
AD1
BC2
CB3
DA4

I want something like 'column value corresponding C min min (col B) result = (col A) - value of the corresponding C column (number)' without having to write 2 select statements. How do I do that?

Thanks in advance

aBBy007



Notes on the system:

2-node 11.2.0.3.4 GI/RDBMS running on RHEL5.

Hello

It is not very similar to your original question.  It would be better if you asked what you really want in your first post, rather than making people to time writing solutions you want not and can not use waste.  Once you see an answer to this question, will you change the question again?

Here's a way to do what you asked:

WITH got_lasts AS

(

SELECT val.thread #.

, MAX (val.sequence #) AS last_standby_seq_received

MAX (CASE

WHEN val.applied = "YES".

THEN val.sequence #.

END

) AS last_standby_seq_applied

V $ archived_log val

Join v$ database vdb WE val.resetlogs_change #.

= vdb.resetlogs_change #.

GROUP BY thread #.

)

SELECT thread #.

last_standby_seq_received

last_standby_seq_applied

last_standby_seq_received

-last_standby_seq_applied AS total_lag

OF got_lasts

ORDER BY thread #.

;

Tags: Database

Similar Questions

  • Find the difference between two numbers (DBL)

    Hi all

    Is there a function in labview other than the subtraction function that can find the difference between the two numbers given?

    Thank you

    Davidson


  • How to find the difference between standard edition and standard edition one

    How to find the difference between oracle database standard edition and standard edition one 64 bit

    (a) using sql
    (b) using the configuration/installation files

    How to find the difference between oracle database standard edition and standard edition one 64 bit

    (a) using sql

    Select * the option of $ v;

    (b) using the configuration/installation files

    opatch lsinventory-details

  • Find the difference between two date and time

    Hi friends,

    I wanted to find the difference between two date and time, but my qury is slightest error "invalid number."

    select sql_step_num,proc_name,run_seqno,start_date,end_date,(to_char(start_date,'HH24-MI-SS') - to_char(end_date,'HH24-MI-SS') ) as ed  
    from eval.EVAL_RUNTIME_DETAILS
    where trunc(start_date) = trunc(sysdate) 
    order by sql_step_num;

    You try to get the feel between two char strings.
    And more difference between two dates gives a NUMBER of days.
    Try this:

    select sql_step_num,proc_name,run_seqno,start_date,end_date,numtodsinterval(end_date-start_date,'DAY') as ed
    from eval.EVAL_RUNTIME_DETAILS
    where trunc(start_date) = trunc(sysdate)
    order by sql_step_num;
    
  • How to find the difference between two dates in time except Sunday

    Hi all

    I have a table, as shown below.
    SQL> select * from test;
    
    TR_ID                                              CREATE_TIME                                                                       CODE
    -------------------------------------------------- --------------------------------------------------------------------------- ----------
    S12341                                             05-JUN-12 12.20.52.403000 AM                                                      1003
    S12342                                             11-JUN-12 11.15.33.182000 AM                                                      1003
    S12342                                             07-JUN-12 12.00.36.573000 PM                                                      1002
    S12343                                             20-JUN-12 12.34.37.102000 AM                                                      1003
    S12343                                             15-JUN-12 11.34.27.141000 PM                                                      1002
    S12344                                             01-JUL-12 10.01.06.657000 PM                                                      1002
    S12344                                             06-JUL-12 12.01.04.188000 AM                                                      1003
    S12341                                             31-MAY-12 11.20.38.529000 PM                                                      1002
    I would like to know the difference between same tr_ids create_time, which should give out in hours except Sunday.

    For example:

    TR_ID: S12344
    1002_Create_time: July 1, 12 PM 10.01.06.657000 (i.e. Sunday)
    1003_Create_time: 12.01.04.188000 AM 6 July 12

    1002 create time is 22:00 Sunday.

    If the query must exclude only the hours of Sunday which is 10 p.m. to Monday 00 h which is 2 Hrs.

    I tried the sub query after doing a search on this forum but I am not getting the desired output.
    SELECT count(*) FROM (SELECT ROWNUM RNUM,tr_id,create_time CT_1002 FROM test c WHERE c.tr_id='S12344' and 
    ROWNUM <= (select (cast(a.create_time as date)-cast((select create_time from test b where a.tr_id=b.tr_id and code=1002) as date)) 
    from test a where a.code=1003 and a.tr_id=c.tr_id) + 1) d 
    WHERE to_char(cast((select create_time from test e where e.tr_id=d.tr_id and code=1002) as date) + RNUM - 1, 'DY') NOT IN('SUN');
    Need help to get the desired o/p

    Hello

    If I unederstand the problem correctly, that's what you want:

    WITH       got_extrema     AS
    (
         SELECT       tr_id
         ,       CAST (MIN (create_time) AS DATE)     AS start_date
         ,       CAST (MAX (create_time) AS DATE)     AS end_date
         FROM       test
         GROUP BY  tr_id
    )
    SELECT       tr_id
    ,       start_date, end_date          -- If wanted
    ,       24 * ( ( ( TRUNC (end_date,   'IW')          -- Count -1 day for every full week
                        - TRUNC (start_date, 'IW')
                 )
               / -7
                  )
                + LEAST ( end_date               -- If end_date is a Sunday
                            , TRUNC (end_date, 'IW') + 6     -- consider it 00:00:00 on Sunday
                     )
                - CASE
                          WHEN  start_date >= TRUNC (start_date, 'IW') + 6     -- If start_date is a Sunday
                   THEN  TRUNC (start_date, 'IW') + 6               -- consider it 00:00:00 Sunday
                   ELSE  start_date
                      END
                )     AS total_hours
    FROM      got_extrema
    ;
    

    I guess that you don't need to worry about fractions of a second. As you did in the code you have posted, I am to convert the TIMESTAMP to date values, because of DATE arithmetic and functions are so much better than what is available for timestamps.

    Basically, it's just to find the number of days between start_date and end_date and multiplying by 24, with these twists:
    (a) 1 day is deducted for each week between start_date and end_date
    (b) if End_date is a Sunday, none of the end_date himself hours are counted
    (c) If start_date is a Sunday, then all the start_date himself hours are counted. Why these hours should be counted? Because 1 day is already being deducted for the week which includes start_date, which contains only this Sunday.

    TRUNC (dt, 'IW') is the beginning of the ISO week containing dt; in other words, 00:00:00 the or before the dt last Monday. This is not the NLS parameters.

    Of course, I can't test without some sample data and the exact results you want from these data. You may need a little something more If start_date and end_date are both on the same Sunday.
    Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • Query to get the difference between 2 totals of 2 different queries

    I wanted to know if it is possible to get the difference between 2 totals of 2 different queries. Let me explain with an example:

    1 application ofst - sum (homepass) Select table 1

    2th query: select sum (homepass) from table2

    Is it possible to display the difference as -

    Select sum (homepass) in table 1 - sum (homepass) from table2

    I know that the above query would give syntax error, but is there a better way or something to get the above done task from a single query.


    Hopefully, my question is clear.


    Please get back with the answer to my query.


    Concerning

    You can always do something like

    SELECT a.cnt - b.cnt
    FROM (SELECT sum(homepass) cnt from table1) a,
          (SELECT sum(homepass) cnt from table2) b
    

    I'd be somewhat dubious, although on a data model that had two tables with the same name of the column where it really made sense to subtract one amount from each other.  This would strongly imply that there should be a single table with an additional column TYPE eventually.

    Justin

  • How to find the difference between two dates in the presentation layer

    Hi gurus,

    Hello to everyone. Today, I came with the new requirement.


    I need to know the difference between a date and the current date in the formula column application presentation layer.by.



    Thank you and best regards,
    Prates

    Hi Navin,

    TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".

    If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...

    hope you understand...

    Award points and to close the debate, if your question is answered.

    See you soon,.
    Aravind

  • What is the difference between these two series: ONE VIDEO and a VIDEO SN184?

    Hello

    Is anyone know the difference between these two serial numbers: A VIDEO and a VIDEO SN184?

    Hi Lennart,

    This might be useful: ONE VIDEO AND ONE NON-VIDEO

    Kind regards

    Sheena

  • How to find the difference between the two timestamp columns

    Dear all,
    Please solve my problem,
    I have Table name of the folder that has the following columns,
    EmpID in the number column, timestamp dat
    who has the following values
    Expand | Select | Wrap | Line numbers
    EmpID dat
    ====== ====
    101 4/9/2012 09:48:54
    101 4/9/2012 09:36:28
    101 4/9/2012 18:16:28
    101 4/10 / 2012 09:33:48
    101 4/10 / 2012 12:36:28
    101 4/10 / 2012 20:36:12
    101 4/11 / 2012 09:36:28
    101 4/11 / 2012 16:36:22
    Here, I need to display the following columns

    EmpID, min (DAT) as start, max (dat) as end and difference (max (dat) - min (dat) for each day,
    for example,.
    End difference EmpID Strart
    101 4/9/2012 09:48:54 09/04/2012 18:16:28 8.28
    Like this.
    3 days different here is so it should return 3 discs with the mentioned columns above,
    Please help me find it.

    Thank you
    Kind regards
    Gurujothi

    Published by: Gurujothi on April 25, 2012 04:45

    Gurujothi wrote:
    Dear Alex,
    Thank you for your reply,
    Depending on whether you are your quesy showing it in hour and minutes format its right but you mention all rows of the query
    If the table has more than 3000 lines then how it is possible to write this much higher request,
    my table with almost 3500 lines.

    You can make a few changes in the above query I posted the last I mentioned?

    Thank you.

    Published by: Gurujothi on April 25, 2012 23:18

    Hello

    You don't need to write whole records 3000 it... alex just wrote that for example have no table as your table...
    so just use the under part of this query as in the previous post, alex:

    select empid, trunc(dat),
           min(dat) as start_dat,  to_char(min(dat), 'hh24:mi:ss') as start_dat_part,
           max(dat) as end_dat, to_char(max(dat), 'hh24:mi:ss') as end_dat_part,
           max(dat)-min(dat) diff, to_char(max(dat)-min(dat), 'hh24:mi:ss') diff_part,
           extract(day from max(dat)-min(dat)) || ' days'
           || ':' ||  extract(hour from max(dat)-min(dat)) || ' hours'
           || ':' ||  extract(minute from max(dat)-min(dat)) || ' mins'
           || ':' ||  extract(second from max(dat)-min(dat)) || ' sekas'
    from trans
    group by empid, trunc(dat)
    

    hope this fixes your need

  • How to find the difference between related areas

    Hi all
    My problem is I have a table in which each woman will be visited maximum 8 times, each woman may or may not
    given a reference in any visit which in turn women will respond to this referral in a next visit
    (not necessarily the next visit), I need to calculate the average number of visits between the visit
    in which the wife received a refferal and visit in which she responds.

    as an example

    woman_id visit_id given_referral respond_to_referral
    -------- -------- -------------- -------------------
    1 1 TRUE NULL
    1 2 TRUE TRUE
    1 3 TRUE NULL
    1 4 TRUE NULL
    1 5 NULL NULL
    1 6 TRUE NULL

    This means that visit 2 response is referral to visit 1 so the difference is 1.
    and the visit 6 response corresponds to the referral in visit 4 so the difference is 4.
    what I can't do is knowing how to know answer to visit 6 associated reference visit 4 No 1 or 2 or 3...

    and I need to find the following table of the foregoing

    woman_id difference between referral and response
    ---------          ---------------------------------------
    1                    1
    1                    2

    quick access to help please

    Published by: M.Jabr on December 14, 2009 08:05
    with t as (
               select 1 woman_id,1 visit_id,'TRUE' given_referral,NULL respond_to_referral from dual union all
               select 1,2,'TRUE','TRUE' from dual union all
               select 1,3,'TRUE',NULL from dual union all
               select 1,4,'TRUE',NULL from dual union all
               select 1,5,NULL,NULL from dual union all
               select 1,6,NULL,'TRUE' from dual
              )
    select  woman_id,
            diff
      from  (
             select  woman_id,
                     visit_id - last_value(case
                                             when given_referral is not null
                                               then visit_id
                                           end
                                           ignore nulls
                                          )
                                over(
                                     partition by woman_id
                                     order by visit_id
                                     rows between unbounded preceding and 1 preceding
                                    ) diff,
                     respond_to_referral
               from  t
            )
      where respond_to_referral = 'TRUE'
    /
    
      WOMAN_ID       DIFF
    ---------- ----------
             1          1
             1          2
    
    SQL> 
    

    SY.

  • Groovy Script to find the difference between Dates

    I am trying to build a script that takes a date from a RequestField and calculates the number of days between this date and the current date (from session).

    So far, I have a problem, the analysis to-date from the RequestField chain. I found this code but it doesn't seem to work...

    date = new Date().parse('yyyy/MM/dd', '1973/07/09')
    

    I get the following error...

    Error Message: groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (java.lang.String, java.lang.String) values: {"yyyy/MM/dd", "1973/07/09"}
    

    Any help would be greatly appreciated.

    Hello

    What version of server? The extract you have here works fine on mine (563).

    This also works for me

    new java.text.SimpleDateFormat('yyyy/MM/dd').parse('1973/07/09')
    

    See you soon

    Nils

  • How to calculate the difference between two numbers in text fields

    Hello, I am fairly new to this, and I am certain that I will be bothered by the simple answer is

    I do a simple calculation... total of total assets - liabilities = net worth

    I have my total assets and my total work of the liability, but is not a subtraction option in the properties of a text field for the Net of a field value.

    I don't know... not any script Java can any who help out me?

    Thank you

    Judy

    You can use the option of simplified field notation, but first your input fields names must be changed so that they do not contain spaces or punctuation. For example:

    TotalAssets - TotalLiabilities

    If you want to use JavaScript, what will be needed if you ever in more complicated calculations, you can use something like the following as the custom fields (net value) calculation script:

    (function () {}

    Get the values of the field as numbers

    var v1 = + getField("total_assets").value;

    var v2 = + getField("total_liabilities").value;

    calculate the value of this field

    Event.Value = v1 - v2;

    })();

    There are no restrictions on domain names when using JavaScript.

  • How to store the difference between two timestamps as a number?

    Hello
    I need to find the difference between 2 variables of timestamp and the result will be stored as a number in minutes?
    as
    declare
    timestamp (7) of the fir_timestamp: = 1 January 2012 13:30 ';
    timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 ';
    c number;
    Start
    c:=((sec_timestamp-fir_timestamp)/(24*60));
    dbms_output.put_line (c);
    end;

    962813 wrote:
    declare

    -fir_timestamp timestamp (7): ='01 - jan - 2012 13:30 ';
    timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 ';  Incorrect type declaration

    fir_timestamp timestamp: = 1st January 12 01.30.00.000000 PM';
    sec_timestamp timestamp: = 1st January 12 02.00.00.000000 PM';
    c number;
    Start
    c: = ABS ((extrait (HEURE de sec_timestamp) - extract (fir_timestamp TIME)) * 60) +.
    ABS ((extrait (MINUTE de sec_timestamp) - extract (fir_timestamp MINUTE)));
    dbms_output.put_line (' interval Min Total:-' | c);
    end;
    /
    declare
    *
    ERROR on line 1:
    ORA-01830: date format picture ends before converting all of the input string
    ORA-06512: at line 6

    Follow what Paul has done...

    In fact, you do not need timestamp, date data type is enough

    SQL> declare
      2     fir_timestamp date :=
      3        to_date('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss');
      4     sec_timestamp date :=
      5        to_date('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss');
      6     c number;
      7  begin
      8     c:= round((sec_timestamp-fir_timestamp)*24*60);
      9     dbms_output.put_line(c);
     10  end;
     11  /
    30
    
    PL/SQL procedure successfully completed.
    

    If you want to place on timestamp

    SQL> declare
      2     fir_timestamp timestamp :=
      3        to_timestamp('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss');
      4     sec_timestamp timestamp :=
      5        to_timestamp('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss');
      6     c number;
      7  begin
      8     c:= round((
      9     to_date(to_char(sec_timestamp,'ddmmyyyyhh24miss'),
     10             'ddmmyyyyhh24miss')-
     11          to_date(to_char(fir_timestamp,'ddmmyyyyhh24miss'),
     12             'ddmmyyyyhh24miss')
     13           )*24*60);
     14     dbms_output.put_line(c);
     15  end;
     16  /
    30
    
  • Do not understand the difference between my models and why they are distributed differently

    I converted a bunch of guest in model systems and I have now a few top group and listed on sub Discover Virtual machines but also have other models in alphabetical order among the guest computers.

    I need know how to find the differences between these models (there are) and why

    they are arranged in this way?

    I have attached a picture of my layout, note both models circled were created from the same guest machine and the content seems to be the same. My host is vSphere ESXi 4.

    Thank you

    Andy

    andykam wrote:

    The hosts and clusters discovered I model right click and select Convert to template. But have listed it under default, after the model to select the virtual machine that is discovered in the wizard. Otherwise, it gets partner and alphabetical?

    exactly

  • Dear gurus: Can u pls explain the difference between VARCHAR2 &amp; NVARCHAR2?

    Dear gurus,

    Can you please explain in simple terms we beginners the difference between VARCHAR2 and NVARCHAR2.

    I have read all the documentation, but I just don't understand?

    What exactly is the advantage of NVARCHAR2?

    When should we use it?

    What are the differences?

    NVARCHAR2 is used only when using non-English characters sets?

    Is there a saving advantage?

    Some say that NVARCHAR2 will give different VARCHAR2 columns values when you use the LENGTH function?

    Thanks in advance

    Published by: user12240205 on October 27, 2011 06:15

    Published by: user12240205 on October 27, 2011 06:15

    CHAR (CHAR, VARCHAR2, LONG, CLOB) data types store data in the database character set. NCHAR (NVARCHAR2, NCHAR, NCLOB) data types store data in the national character set. The national character set can be either AL16UTF16 (the default) or UTF8 (rare compatibility requirements). The database character set can be one of the dozens of characters supported by Oracle games. The recommended database charset is AL32UTF8.

    AL16UTF16 and are all two AL32UTF8 Unicode - UTF-16BE and UTF-8 encodings, proportionally.

    The benefits of the NCHAR data types:

    -They are guaranteed to Unicode data types, in other words, any database from Oracle 9.0 can store Unicode data into NCHAR, NVARCHAR2, and NCLOB columns.
    -Storage Unicode languages of South and East Asia is more compact in relation to AL32UTF8 AL16UTF16. AL16UTF16 storage is only possible in NCHAR data types.

    (Serious!) cons of NCHAR data types:

    -You need a special coding in client access API to ensure that the data you want to store NCHAR data type columns is not through conversion to character data, lose the advantage 'warranty Unicode.
    -There are Oracle components that do not support the data types NCHAR, including Oracle Text and XDB.
    -It's confusing and prone to work with two character sets of database, the database character set and the national character set.
    -Storage of most European languages is more compact in AL32UTF8 compared to AL16UTF16.

    Advice from the Oracle:

    -For any new database, create it with the character AL32UTF8 and forget types NCHAR data.
    -For all existing applications to make multilingual, migrate the database backend to AL32UTF8 and forget the NCHAR data types.
    -For any database existing non-Unicode serving a large legacy application system that is too expensive or impossible migrate to Unicode, you are invited to add a minor module which must support multilingual data and for which a separate database makes little sense, you can consider NVARCHAR2 columns for these multilingual data.

    -Sergiusz

Maybe you are looking for

  • new language support

    Hello I am from Luxembourg. A small country in Europe. For us here, it is difficult to find any electronic device that supports our Luxembourg native. So go instead of German or in french or in English. So I wanted to ask if there is any possibility

  • Photosmart C4880 Mac OS x 5.8

    My Photosmart printer was purchased from the United States.  Safe supply site indicated ink cartridges new 350 (XL) and 351 (XL) (screenshot attached) so far the black cartridge is not compatible. Please notify.

  • f4u14ea model 15d012sv: lack of drivers after installing win7!

    Hello! I installed windows 7 64 bit on my laptop (before there was windows 8) I can't find the drivers with the support tool you have it please help me! my laptop model f4u14ea model 15d012sv missing drivers are 3D video controller PCI\VEN_10DE & DEV

  • How to restore the original admin account

    I created a new account to do the type, the administrator!  Changing type of the original of the limited account administrator.  So I could delete the original account that was the administrator. Problem: User accounts for only digital shows with lim

  • Support for Office 2013 Archive Manager

    Hello What Archive Manager will support Exchange2013, Shrepoint 2013 and Lync 2013?