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

Hello,
I want to find the difference between 2 numbers from same column corresponding to some condition of another column. How do i that?
Eg: Say I have a table with 3 columns A, B & C.
A -> Varchar2
B -> Varchar2
C -> Number
A
B
C
A
D
1
B
C
2
C
B
3
D
A
4
I want something like "value of column C corresponding to min(col A) - value of column C corresponding to min(col B) = result (number)" without having to write 2 select statements. How do I do that?
Thanks in advance
aBBy007
System notes:
2-node 11.2.0.3.4 GI/RDBMS running on RHEL5.

Thank you.
That solved part of a problem. Now what if I want to satisfy a condition?
Considering the same above table, say I want to "value of Col_C when value of Col_A='D' - value of Col_C when value of Col_B='C'"?
abby007
I am trying to query the v$archived_log view. And currently 'm running the below 2 queries to find out the updated archives on the DR site and then manually subtracting it:
PhyStdby: SQL > select thread#, max(sequence#) "Last Standby Seq Received"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
group by thread# order by 1;
PhyStdby: SQL > select thread#, max(sequence#) "Last Standby Seq Applied"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
and applied='YES'
group by thread# order by 1;
I want to combine the above 2 queries so that I get a response like:
Thread#
Last Standby Seq Received
Last Standby Seq Applied
Total Lag
1
33778
33770
8
2
70244
70242
2
3
46972
46971
1

Similar Messages

  • Find difference between two numbers (DBL)

    Hello All,
    Is there a function in labview other than subtraction function that can find the difference between the two given numbers?
    Thanks,
    Davidson
    Solved!
    Go to Solution.

    I think if he wanted to find absolute value he would have mentioned it.
    And not asked about other function for taking difference.
    Do you want to fight over this? When it is mentioned "DIFFERENCE" and not "ABSOLUTE" value.
    Anyways..Will fight tomorrow. I am going home.
    Best of luck
    Gaurav k
    CLD Certified !!!!!
    Do not forget to Mark solution and to give Kudo if problem is solved.

  • Difference between two numbers in percentage.

    Hi,
    How to find difference between 2 numbers in percentage.
    Is there any standard function module.
    For example. I m having two numbers.
    25 & 31. I want to find how many percentage 25 is different from 31.
    Thanks in advance.

    hi,
    manual coding would be like this,
    data: no1 type i,
            no2 type i,
            no1per type d,
            no2per type d,
            diff type d.
    no1per = no1 / 100.
    no2per = no2 / 100.
    if no1per >= no2per
    diff = no1per  - no2per.
    write:/10 '% diff of',no1,'and',no2,' is',diff.
    else.
    diff = no2per  - no1per.
    write:/10 '% diff of',no2,'and',no1,' is',diff.
    if helpful reward some points.
    with regards,
    Suresh Aluri.

  • Finding difference between 2 databases

    Hi Folks,
    I have the following problem:
    I have 2 databases, database old, database new. Database new has modified/removed/added/inserted rows. Also columns in the db can also be modified. So what I have to do is to find the set of SQL statements which if I execute on database old, will make database old same as database new. Modification is only in data, not triggers etc.,
    I have explained my manager that this is not very easy to implement. Even finding difference between 2 DB is not trivial. Do you guys have any suggestion for me? whether in terms of implementing it or even convincing my boss is fine :)
    Are there any open source tools to do this? I am in big trouble now :(
    Thanks,

    Unless there is some other goal that you have not mentioned this is fairly easy.
    Just delete all the tables from the old database using SQL delete tables and then create new tables and populate them with data from the new database.
    Your SQL is basically just a serialization of the data in your new database.
    Anything else that you could do, such as calculating the differences from the one database to the other, and then creating a minimal edit list that will make the least possible number of changes must be weighed against the time it will take to write the code to compute the differences, the time it will take to debug the code and convince yourself that it is doing the right thing, and the time it will take to actually run.

  • Find difference between date

    I need to know how i can find difference between date
    like Joining date: 01-jan-2009 Today 10-jan-2010 result will be "1 year 10 days"
    I need it in Oracle forms 6i. plz help me...

    Hi,
    In oracle forms you can use
    RESULT :=
    TRUNC ((:date2 - :date1 + 1) / 365)
    || ' year and '
    || MOD (:date2 - :date1 + 1, 365)
    || ' days';
    in sql you can use
    SELECT TRUNC ((:date2 - :date1 + 1) / 365)
    || ' year and '
    || MOD (:date2 - :date1 + 1, 365)
    || ' days'
    FROM DUAL;

  • Find Differences between two tables at column level

    Hi,
    I have 2 tables one live table and the other History table..
    If i have to find differences between live table and the latest version in the History table and also find which column got chaanged
    How would i do that for a table which has many columns and i need each column for which the value has changed for a id
    for ex:
      Table 1   (LIve)                           Table 2 (History)
    ID col1     col2    Version               ID       col1     col2    Version
     1   ABC     123     V1                     1       ABCD   123     v2
     2   NBS     1234   V1                     2        NBS     123     V2
    Result set should be 
    Result Set:
    ID col which changed
    1    col1
    2    col2   
    Because the values for that column had been changed
    Except gives me all the differences not just the column level ..

    The dynamic version using schema views... :D
    --Build a coulple OF testing tables to play with
    CREATE TABLE dbo.Table1 (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    Col1 INT,
    Col2 INT,
    Col3 INT
    CREATE TABLE dbo.Table2 (
    ID INT IDENTITY(1,1) PRIMARY KEY,
    Col1 INT,
    Col2 INT,
    Col3 INT
    INSERT dbo.Table1 (Col1,Col2,Col3) VALUES
    (123,456,789),
    (111,222,333),
    (444,555,666),
    (777,888,999),
    (321,345,769),
    (179,753,758),
    (362,362,236),
    (856,874,896),
    (821,729,324)
    INSERT dbo.Table2 (Col1,Col2,Col3) VALUES
    (123,456,789),
    (111,999,333), --col2 diff
    (444,555,666),
    (777,888,999),
    (321,345,123), --col3 diff
    (179,753,758),
    (362,362,236),
    (234,874,896), --col1 diff
    (821,729,324)
    And then the actual solution...
    DECLARE
    @t1 VARCHAR(10) = 'Table1',
    @t2 VARCHAR(10) = 'Table2'
    IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
    SELECT
    c.TABLE_SCHEMA,
    c.TABLE_NAME,
    c.COLUMN_NAME,
    c.ORDINAL_POSITION,
    CASE WHEN u.COLUMN_NAME IS NOT NULL THEN 1 ELSE 0 END AS PK
    INTO #temp
    FROM
    INFORMATION_SCHEMA.COLUMNS c
    JOIN INFORMATION_SCHEMA.TABLES t
    ON c.TABLE_NAME = t.TABLE_NAME
    AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
    LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE u
    ON c.COLUMN_NAME = u.COLUMN_NAME
    AND c.TABLE_NAME = u.TABLE_NAME
    AND c.TABLE_SCHEMA = u.TABLE_SCHEMA
    AND OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
    WHERE 1 = 1
    AND t.TABLE_TYPE = 'BASE TABLE'
    AND c.TABLE_NAME IN (@t1,@t2)
    ORDER BY
    c.TABLE_SCHEMA, c.TABLE_NAME, c.ORDINAL_POSITION
    DECLARE @select VARCHAR(MAX)
    SELECT @select = COALESCE(@select + ', ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
    FROM #temp AS t
    ORDER BY t.TABLE_NAME, t.ORDINAL_POSITION
    DECLARE @from VARCHAR(MAX)
    SELECT @from = COALESCE(@from + ' FULL JOIN ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME
    FROM #temp AS t
    WHERE t.PK = 1
    ORDER BY t.TABLE_NAME
    DECLARE @on VARCHAR(MAX)
    SELECT @on = COALESCE(@on + ' = ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
    FROM #temp AS t
    WHERE t.PK = 1
    ORDER BY t.TABLE_NAME, t.ORDINAL_POSITION
    DECLARE @where VARCHAR(MAX)
    SELECT @where = COALESCE(@where + CASE WHEN t.TABLE_NAME = @t1 THEN ' OR ' ELSE ' <> ' END, '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
    FROM #temp AS t
    WHERE t.PK = 0
    ORDER BY t.ORDINAL_POSITION, t.TABLE_NAME
    DECLARE @sql VARCHAR(MAX) = '
    SELECT ' + @select + '
    FROM ' + @from + '
    ON ' + @on + '
    WHERE ' + @where
    EXEC (@sql)
    HTH,
    Jason

  • Find a range of numbers in one cell and output in another

    Here I am again with something I just can't seem to find an answer to:
    I need to find the range of numbers in one cell and place that value in another, like so:
    Cell A1 says: "3 - 8"
    Cell A2 returns: 5
    Any simple formula to do this?

    Hi gunkie83,
    Yvan's formula does perform properly. He stated: Here the decimal separator is comma so Numbers use the semi-colon as parameters separator but the formula is OK. CAUTION, here I left the semi-colons.
    Yvan is in France using the French version of iWork. For the U.S.A. semicolons need to be changed to a comas as I have in the following formulae.
    =VALUE(LEFT(A,SEARCH("-",A)-1))-VALUE(RIGHT(A,LEN(A)-SEARCH("-",A)))
    this returns -5
    =ABS(VALUE(LEFT(A,SEARCH("-",A)-1))-VALUE(RIGHT(A,LEN(A)-SEARCH("-",A))))
    this returns 5
    One important observation in cell A2 the text reads as 3 - 8 not 3-8. Also it can be inputted as 3 -8 but not 3- 8. Watch those spaces. Fun huh.
    Hope this helps. Again Yvan thank you.
    Cordially,
    RicD

  • Difference between My SAP & Business One

    Hi Freinds,
                   Can anyone tell me what is the main difference between My SAP, Businees One & Business Suite? Please explain.
    Thanks & Regards
    Saeed Arif

    Hi,
    SAP Business One (SBO) is solution for small enterprises (SME or SMB) market built from scratch on MS Windows platform. It has following functional areas:
    Financials
    Sales opportunity management
    Sales u2013 A/R
    Purchasing u2013 A/P
    Business partner management
    Banking
    Inventory
    Production
    Material requirements planning (MRP)
    Service management
    Human resources management
    Reporting
    Refer following links for more details;
    [mySAP BS, ERP, ECC, BBD, A1S, AIO, SBO|http://sapport.blogspot.com/2008/08/no-clue-between-mysap-bs-erp-ecc-bbd.html]
    [SAP Business One|http://it.toolbox.com/blogs/crm-trends/sap-business-one-4120]

  • Find and replace an item in one column only

    I have tried and tried and I cannot work out how to find and replace an item in one column only.
    For example one column has a letter followed by a number which varies in length.
    I want to find and repace the letters with nothing leaving the numbers only.
    But when I try to do this all the letters in the spreadheet are replaced, not just in the column I have selected.
    Help please....

    Hi 8'
    Use a formula.
    Insert a (temporary) auxiliary column to the right of the one for which you want to male the changes.
    Assuming you description is accurate—every entry in the column consists of a letter followed immediately by a number of one or more digits—the problen could also be stated as  "How do I strip the first character from a string?"
    Here's a sample. Letter followed by number in column B; number part without leading letter i column C:
    Formula:
    C2, and filled down to end of column: =RIGHT(B,LEN(B)-1)
    When the formula has done its work:
    Select all of column C (except the ehader row cell), and Copy.
    Select cell B2, and go Edit > Paste Values.
    Select column C again and go Table (menu) > Delete column.
    Regards,
    Barry

  • Bestway to find difference between two roles in quality and production

    We have a process of collecting su53 dump and then analyze for missing authorization . However some time although everything works fine in quality , it fails in production . Hence I want to know a simple methodology to compare roles in quality and production to know difference ... Can anyone share best methodolgy being used in your setup ?
    NPB

    (1)How to find the difference between two dates at Universe level and at report Level in IDT?
    DaysBetween ([Sale Date];[Invoice Date]) returns 2 if [Sale Date] is 15 December 2001 and [Invoice Date] is 17 December 2001.
    (2) How to change format of dates from YYYY/MM/DD to DD/MM/YYYY in IDT at prompt level ?
    =FormatDate(ToDate(YOUR DARE OBJECT);"YYYY/MM/DD");"dd'/'MM'/'yyyy")
    =To_Char (object name, required format)
    Find the below link for more info.
    http://scn.sap.com/community/semantic-layer/blog/2014/04/18/bi41-business-layer-enhancements--create-display-format
    (3)What is VIEWS in IDT of data foundation layer when we right click? could u plz give one example where exactly we use VIEWS?
    A custom data foundation view is a subset of the data foundation Master view. You can use views when editing a large data foundation, and interested in working with a subset of tables. You can define multiple custom views for the data foundation due to the complexity of the data warehouse.
    Essentially, need created views for each individual star scheme (like Sales, Production, Finance, Accounting, etc.) plus a view for eachcomplex dimension structure (like Business Partner, Material, Customer, Plant etc.),
    Find the below link for more info.
    http://scn.sap.com/docs/DOC-54422
    (4) How to represent & report my IDT data in dashboards? could u plz explain the steps?
    Please find the below link: http://scn.sap.com/docs/DOC-27559

  • Find difference between two vectors ?

    Hi,
    I have two vectors, the first contains:
    v1.add("1");
    v1.add("2");
    the second:
    v2.add("1");
    Now I want to print out the difference between both.
    Does anybody have en idea ?
    Regards
    Micha

    Yep, that should definitely do it. I think the point ssav is trying to make is that to solve this problem we need to know your actual requirements. "the difference between" is too vague. Here are some things to think about:
    - Is position important? That is, is a List containing 1 and 2 the same as a List containing 2 and 1 or different?
    - If List A contains 1,2,4,5,6 and List B contains 1,2,3,4,5,6 what would you want to see?
    - What if List A contains 1,2,3 and List B 1,2,2,3?
    - What if List A contains 1,2,3 and Lits B 1,2,and a java.lang.NullPointerException?
    You're probably starting to see that this is not as simple as you thought. Come back with more specific requirements and you may get better help.

  • Matrix to find differences between OIM11g R1 and R2

    Friends,
    We are 50% completed developing OIM 11gR1. But now, R2 came out.
    I would like to know the main differences between OIM 11gR1 and OIM 11gR2 so that I can convince my client to go for R2 rather than R1.
    If there is any matrix which will show these differences, please let me let me know.
    I would like to know the differences for the below.
    1) Business wise
    2) Technical development
    3) End user stand point

    1) Business wise
    R2 is much more business friendly. It's structure is now simple and more secure than that of 11Gr1. Each and everything is request based. Shopping cart functionalities has beedn added. So manual provisioning is possible for multiple user for multiple resources at a single time.
    2) Technical development
    Most of things are simpleified for development as well. Few differences could be, we don't have seperate process and object form, same form is references everywhere. Template level approvals are not there. All requests are routed through SOA. You need to have skills on SOA as well.
    3) End user stand point
    We have two consoles now. End user can work on identity console where as admins can work on sysadmin console. Structure is seperated for both kind of users. Also UI is less heavy than that of 11Gr1.
    You can ask Oracle for proper document on it.
    regards,
    GP

  • Finding difference between Max date and Min date from single date field

    Dear Experts,
    Here I am with a scenario where i didnt find any solution in SDN and in most threads it is unanswered.
    I have 1 KF which is a date field. With reference to Serial no, I want to find out the Max and Min date from the same KF. I created 2 CKF where the same KF is used in both CKF to find the Min and Max dates,
    Ex:
    Serial No | Material | Actual Del date | Max | Min | Difference
    0123 | 300012 | 01.01.2009 | 31.01.2009 | 01.01.2009 | 30
    0123 | 300013 | 07.01.2009 | 31.01.2009 | 01.01.2009 | 30
    0123 | 300018 | 15.01.2009 | 31.01.2009 | 01.01.2009 | 30
    0123 | 300014 | 30.01.2009 | 31.01.2009 | 01.01.2009 | 30
    0124 | 300019 | 02.01.2009 | 10.01.2009 | 02.01.2009 | 8
    0124 | 300012 | 06.01.2009 | 10.01.2009 | 02.01.2009 | 8
    0124 | 300017 | 10.01.2009 | 10.01.2009 | 02.01.2009 | 8
    This is the way how I want the output where now I am able to get the values right till Max and Min and not the difference. I even created the 3rd CKF the find the difference but it is not working.
    How can I find the difference between the Max and Min dates?
    Regards,
    Chan

    Hi
    You have FM --DAYS_BETWEEN_TWO_DATES you can use this while Customer Exit.
    Try to Have 2 RKF for Min Data and Max Date and create a formula/CKF on the same ..
    Hope it helps

  • To find difference between two dates

    Hi all,
    I am new to this forum and oracle.
    I want to get the difference between two dates. My query is as below...
    sqlserver_utilities.datediff('YY', startdate,enddate)
    I want the difference in year.
    Please help me. It's really urgent.
    Thanks in advance.
    Regards,
    Inam

    Select to_char(enddate,'YY') - to_char(startdate,'YY') fromPLEASE don't do that. There are so many things wrong with it...
    for example:
    1). Why are you subtracting character data types?
    2). What if the start date is 1999 and the end date is 2000? Do you expect to get a difference of -1?
    3). What if the start date is 1 Jan 2000 and the end date is 31 Dec 2000? Do you expect to get 0 instead of 1 or .997?
    4). Why would you convert dates to something else when they are inherently subtractable.
    5). There are obvious points in the OP's "specification" that are vague - the best thing (after telling them to search, of course since this has been answered a million times already) would be to try to clarify the spec.
    John

  • SQL Query issue find difference in records

    Hi All,
    I am using oracle 10g. I need urgent help in finding difference in records based on date:
    I have table sales as below:
    salesman SALES_COUNT DATE
    JOHN 20 04/01/2012
    DENNY 15 04/01/2012
    JOHN 30 04/02/2012
    DENNY 30 04/02/2012
    JOHN 45 04/03/2012
    DENNY 50 04/03/2012
    SALES_COUNT is increasing for sales man with date. Its like cumulative count. John has total sales from 04/01/2012 to 04/03/2012 is 50 and same case with Denny. This SALES_COUNT will keep on increasing with dates as sales keep adding in the table for each salesman.
    But i want to have seprate counts for each salesman.
    for e.g: SALES_COUNT JOHN on 04/02/2012 is 30-20 =10
    SALES_COUNT JOHN on 04/03/2012 is 45-30 =15
    SALES_COUNT DENNY on 04/02/2012 is 30-15 =15
    SALES_COUNT JOHN on 04/03/2012 is 50-30 =20
    Please help me with this scenario and let me know if need more information. I will greatly appreciate your help.
    Thanks.

    Does this give you what you want?
    with t as (
         select 'JOHN' salesman, 20 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 15 sales_count, to_date('04/01/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 30 sales_count, to_date('04/02/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'JOHN' salesman, 45 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
         union all
         select 'DENNY' salesman, 50 sales_count, to_date('04/03/2012', 'mm/dd/yyyy') sale_date from dual
    select salesman,
           sales_count sales_todate,
           sale_date,
           sales_count - lag(sales_count, 1, 0) over (partition by salesman order by sale_date) daily_sales
    from t
    SALESMAN,SALES_TODATE,SALE_DATE,DAILY_SALES
    DENNY,15,4/1/2012,15
    DENNY,30,4/2/2012,15
    DENNY,50,4/3/2012,20
    JOHN,20,4/1/2012,20
    JOHN,30,4/2/2012,10
    JOHN,45,4/3/2012,15
         

Maybe you are looking for