Take the difference of two tables
Hello
I have two tables where in I need to take the difference between the two columns of different tables and show as decimal below:
Table A
Name, salary
x 10.5
y - 10.32
z 5
Table B
Name, salary
x 10.5
y - 10.32
z 3
a 12
Output:
Name_A, Name_B, salary, remarks
x, x, 0, no diff
y, y, 0, no diff
z, z, 2 Diff is here
, one, no data, no data from the previous
Hello
Try ythis:
with table_a as
(
SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
SELECT THE NAME OF 'Z', 5 DOUBLE SALARY
)
table_B as
(
SELECT 'X' NAME, SALARY, 10.5 DUAL UNION ALL
SELECT THE NAME OF 'Y',-10.32 SALARY OF DOUBLE UNION ALL
SELECT THE NAME OF 'Z', 3 DOUBLE UNION ALL SALARIES
SELECT 'A' NAME, SALARY 12 DUAL FROM
)
SELECT
COALESCE(A.NAME,B.NAME) NAME
, NVL (TO_CHAR (A.SALARY - B.SALARY), 'NO DATA') SALARY
, CASE WHEN A.SALARY - B.SALARY = 0 THEN 'NO DIFFERENCE '.
WHEN B.SID IS NULL, "NO DATA OF THE PREVIOUS.
WHERE B.NAME IS NULL, "NO DATA FROM NEXT.
ANOTHER 'DIFFERENCE IS THERE.
END NOTEOf
TABLE_A HAS
TABLE_B FULL OUTER JOIN B ON (B.SID = B.NAME)
;NAME SALARY NOTE
---- ---------------------------------------- ---------------------
X 0 NO DIFFERENCE
Y 0 NO DIFFERENCE
Z 2 THE DIFFERENCE IS THERE
A NUMBER OF DATA NO DATA FROM THE PREVIOUS
Kind regards
Peter
Tags: Database
Similar Questions
-
The most elegant way to get the difference between two tables - not least!
Hello
Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.
My aim is to compare the two, such as; -
When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.
When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.
Where the data exist in REVISED I want the REVISED value.
I can see how I can do this, see below, but is there a more elegant solution?
Data for the ORIGINAL table
Data for the REVISED tableselect '801040' entity, '2186' expense_type, 234000 budget from dual union all select '801040' entity, '3001' expense_type, 1000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P135' expense_type, 43000 budget from dual
Desired outputselect '801040' entity, '2186' expense_type, 235000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P139' expense_type, 56000 budget from dual
ENTITY EXPENSE_TYPE DIFFERENCE
------ ------------ ----------
801040 2186 1000
801040 3001-1000
801040 P135-43000
801040 P139 56000
5 selected lines.
Code current to achieve this, is there a better way?
Thanks a lot for your comments,.select original.entity , original.expense_type , (nvl(revised.budget,0) - original.budget) as difference from original , revised where original.entity = revised.entity(+) and original.expense_type = revised.expense_type(+) and (nvl(revised.budget,0) - original.budget) != 0 union all select revised.entity , revised.expense_type , revised.budget as difference from revised where not exists (select 'x' from original where original.entity = revised.entity and original.expense_type = revised.expense_type) and revised.budget != 0
Robert.
Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads upSQL> with original 2 as 3 ( 4 select '801040' entity, '2186' expense_type, 234000 budget 5 from dual 6 union all 7 select '801040' entity, '3001' expense_type, 1000 budget 8 from dual 9 union all 10 select '801040' entity, 'P132' expense_type, 34000 budget 11 from dual 12 union all 13 select '801040' entity, 'P135' expense_type, 43000 budget 14 from dual 15 ) 16 , revised 17 as 18 ( 19 select '801040' entity, '2186' expense_type, 235000 budget 20 from dual 21 union all 22 select '801040' entity, 'P132' expense_type, 34000 budget 23 from dual 24 union all 25 select '801040' entity, 'P139' expense_type, 56000 budget 26 from dual 27 ) 28 select * 29 from ( 30 select nvl(o.entity, r.entity) entity, 31 nvl(o.expense_type, r.expense_type) expense_type, 32 nvl(r.budget,0) - nvl(o.budget,0) budget 33 from original o 34 full join revised r 35 on o.entity = r.entity 36 and o.expense_type = r.expense_type 37 ) 38 where budget <> 0 39 / ENTITY EXPE BUDGET ------ ---- ---------- 801040 2186 1000 801040 P135 -43000 801040 3001 -1000 801040 P139 56000 SQL>
-
Difference between two tables (ORA-01722)
I am trying to get the difference of two tables on two databases.
Walker I run the script below, it gives me a result that is not accurate.
Select name, creation_time of v$datafile@REMOTE_database.com
However, when I run this script, I get an accurate count of the difference. How can I list the exact number instead of only to count the difference? Want lists all five name missing on table 2.
2 LESS THAN
3 select name, creation_time from v$ datafile;
I get 14 ranks of foregoing.
SQL > SELECT a.cnt - b.cnt
> count 2 (name) select cnt (of v$datafile@REMOTE_database.com) a, b3 (select count (name) NTC v$ datafile);
edited by: Albert Zaza on July 19, 2010 11:19
A.CNT - B. CNT
-----------
5have you tried:
select trim(upper(name)) from v$datafile@REMOTE_database.com MINUS select trim(upper(name)) from v$datafile;
-
Take the time between two values
Hi people,
I have a problem and I know idea how to solve... I need help.
The problem is I want to take the time between two values max as you can see in the chart.
For example, in the image that I have add
4.5 - 1 840 = 2.66
And enter this value in the 'time between mostra '.
It's that I want...
But what I think is very complicated, because I don't know how to take the time correctly and does remove...
Thank you very much
Any solution?
Hi jocuma,
I tried something and hope that helps u.
Just create two arrays of temperature and voltage. First of all, I'll get the value of the voltage when it is more of a certain value and that same index to get the value of time and store in the shift register.
When I get the second higher than the limit value, I'll get time and subtract the previous value.
-
Take the minimum value for table data
I'm storing test data in a table, with the hope that I can output the minimum value of the data. So far, I have used the table of max/min but can't make it work how I want. The test runs continuously in a loop of the holder. I get the minimum values in the table, but I would like to change the number of samples that the table contains, before it generates a minimum. The other option is that I run the test for a period of time (e.g. 3 seconds) and the table stores the data for this time then output 1 minimum value for the entire period.
My current configuration VI is attached.
Very appreciated
Chris
The size of the array in your VI is determined by the number of samples that you collect in your DAQ assistant, who is now 100 samples. Never more, never less.
How many samples do you want before you determine the minimum?
Maybe what you really want to do is to build the table in the while loop and store it in a shift register, and when the loop has repeated enough times, then you take the minimum of built table.
-
How to quickly find the difference of two version of RPD?
Hi all
Someone has a good idea to quickly find the difference of two versions of the RPD in the project?
Kind regards
AnneThis could be a help for you
http://varanasisaichand.blogspot.com/2010/03/how-to-merge-two-repositories.html
http://www.rittmanmead.com/2010/07/OBIEE-11gr1-incremental-patches-to-the-RPD/See you soon,.
KKPublished by: Kranthi.K on December 7, 2011 21:41
-
What is the difference between a table and a subform?
What is the difference between a table and a subform in LC forms? Please post your answers about the merits and demerits of using subforms instead of tables.
Hello
a table is simply a set of subforms with a particular role.
It is easier to handle the tables if they must be dynamic (add or remove lines, show or hide lines when page breaks appear etc..).
And Designers UI has some dialogue prepared in the object palette to simplify the settings of the tables.
For subforms, dialog boxes are more frequent, so you have yourself a little more script.
But at least you can do everything with subforms as you can do with tables.
The only one who is not very good with tables we work when you wrap arrays in other tables.
-
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,
PratesHi 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 -
Kindly help me with the request to find the data in two tables
Hello Guru
Kindly help me to recover the data from two tables-
BASEBALL
LEGAL_ENT_ID (PK)
GAME_ID (FK)
LEGAL_ENT_NM
INACTIVE_DT
DATE OF INS_TS
INS_LOGIN
DATE OF UPD_TS
UPD_LOGIN
FOOTBALL
GAME_ID (PK)
BRKR_NM,
BRKR_ISR_ID
BROKER_SYMBOL
INACTIVE_DT
BRKR_SWIFT_FLG
BRKR_INTERNAL_FLG
BRKR_CATEGORY
UPD_TS
MINORITY_FLG
BROKER_TYP
STATUS
INS_TS
INS_LOGIN
UPD_LOGIN
APP_USER
ACTIVE_FLG
and if I want fecth data from these two tables according to the following condition then it is fine with the suite of applications.
1 select distinct values only table of BASEBALL by using the following query.
SELECT DISTINCT B.GAME_ID as 'CLEARING GAME ID', B.BRKR_NM "NAME of THE GAME of COMPENSATION" OF BASEBALL A, FOOTBALL B WHERE A.BROKER_RELATION_CD IN ('FUTBRKR1', 'FUTBRKR2') AND A.GAME_ID = B.GAME_ID
2 Select all the table BRKR_NM OF FOOTBALL as well by using the query - next
SELECT GAME_ID "RUNNING GAME ID", 'NAME OF THE GAME OF EXECUTION' BRKR_NM SOCCER
Now, my query is that--
I want a query that gives me a combination of above mentioned queries... and if I tried to use Union or Union All, then she is not giving me the result as expected.
I like the result to look like who has a few conditions such as -
1 - the records in the table Football are high vs Baseball table because there is no condition to filter the records of the Football.
2 - football is a superset of records and Baseball is a subset.
3 - COMPENSATION NOM_JEU and RUNNING NOM_JEU may return the same values as well.
I want the result to be in the following form-
EXECUTION ID GAME | NAME OF THE GAME TO RUN. COMPENSATION ID GAME | DELETE THE NAME OF THE GAME.
2123 test1 2345 test5
2456 test10 2456 test10
Thanks in advance. Kindly help me.
Published by: user555994 on January 4, 2011 23:48In the output you want.
All the values of baseball;
Values of football that are matched;
But on what condition you want to match? -
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 it warns Oracle to use an index for the join of two tables...
How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?
O.K. I think I should explain what I mean:
When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.
I have two tables: table A and table B.
Table A has 4,000,000 entries and table B has 700,000 entries.
I have a join of two tables with a numeric column as join criteria.
There is an index on this column in A table.
So I instead of
I want to usewhere (A.col = B.col)
in order to avoid Oracle using the index.where (A.col+0 = B.col)
When I use the join in a select query, it works.
But when I use the join as inline in an update statement I get the error ORA-01779.
When I remove the '+ 0' the update statement works. (The column is unique in table B).
Any ideas why this happens?
Thank you very much in advance for any help.
Hartmut cordiallyYou plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html
-
display the data in two tables.
Hi considers the following data
I want to join these two tables and result the followingWITH table1 AS ( SELECT 111 userid, To_Date('7/31/2010','mm/dd/yyyy') dt FROM dual UNION ALL SELECT 111 userid, To_Date('8/1/2010','mm/dd/yyyy') dt FROM dual UNION all SELECT 111 userid, To_Date('8/2/2010','mm/dd/yyyy') dt FROM dual UNION ALL SELECT 111 userid, To_Date('8/3/2010','mm/dd/yyyy') dt FROM dual UNION ALL SELECT 111 userid, To_Date('8/4/2010','mm/dd/yyyy') dt FROM dual UNION ALL SELECT 111 userid, To_Date('8/5/2010','mm/dd/yyyy') dt FROM dual UNION ALL SELECT 222 userid, To_Date('2/28/2010','mm/dd/yyyy') dt FROM dual UNION all SELECT 222 userid, To_Date('3/5/2010','mm/dd/yyyy') dt FROM dual UNION all ), mydates AS ( SELECT To_Date('7/31/2010','mm/dd/yyyy') dt1, To_Date('8/4/2010','mm/dd/yyyy') dt2 FROM dual UNION ALL SELECT To_Date('2/28/2010','mm/dd/yyyy') dt1, To_Date('3/5/2010','mm/dd/yyyy') dt2 FROM dual )
Basically, I join two tables, take dt from table1 and look into mydates. If the data match then display dt and DM2.DT DT2 7/31/2010 8/04/2010 8/01/2010 8/01/2010 8/02/2010 8/02/2010 8/03/2010 8/03/2010 8/04/2010 8/04/2010 8/05/2010 8/05/2010 2/28/2010 3/5/2010 3/5/2010 3/5/2010
If the date in table1 does not match date in t1d in mydates, then display the data but dt and DM2 there same date.
for example,.
7/31 in table1 is 7/31 in mydates so I show 7/31 dt and DM2 as 8/4(from mydates).
now 8/01 does not match all lines in my dates so dt should be 8/01 and T2D should be 8/01. same logic applies to the other lines
can someone write a query that gives the above result? Thank youHello
If you want all lines of table1 (attached to mydates when this is possible, but even when there is no match) then use an outer join:
SELECT t.dt , NVL (m.dt2, t.dt) AS dt2 FROM table1 t LEFT OUTER JOIN mydates m ON t.dt = m.dt1 ORDER BY t.dt ;
-
How to calculate the difference between two times by the NUMBERS
I'm so bothered by the fact that I can't understand that.
Cell B2 - 08:00
Cell C2 - 10:50
(How can cell D2 - I get this cell to calculate the difference and say 02:50?)
I know it's probably one of the most basic operations, but for the life of me I can't understand it. The cells B2 and C2 are formatted for a 24-hour clock. But if I tell the system to just subtract the two, I get "0,118. Everything I find on the forum search goes beyond what I need. Can someone help me?
Thank you
Hi sapirs,
Departure and arrival of the cells are in Date and time with Date format: no and time: 24-hour clock.
Formula in D2 (fill down)
= C2−B2
The results become a duration format, but under automatic (numbers automatically worth this format)
If you wish, you can change the cells of lasting results.
What Data Format have your result cells?
Kind regards
Ian.
-
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
-
Delete rows in a table when the columns from two tables match
Hello
I have following two tables.
===========================================
create the table empbooth as
(
Select 1 empid, 1 double cabin Union all the
Select option 2, Union 1 double all the
Select 3, Union 1 double all the
Select option 4, Union 2 double all the
Select option 5, 2 double
);
create the table attsht as
(
Select 1 empid, 240 reg, 0 unpaid all double union
Select option 2, reg 200, 0 unpaid of all the double union
Select 3, 240 reg, 0 unpaid all double them union
Select 4 480 reg, 0 unpaid all double union
Select 5 240 reg, unpaid double 0
);
=================================================
I want to remove rows from attsht where corresponding booth (which is stored in the empbooth table) is 1.
The condition is 'where attsht.empid = empbooth.empid and empbooth.booth = 1 '.
I use oracle 10g.
Help, please
delete from attsht where a.empid in (select b.empid from empbooth b where b.booth = 1)
or
remove from attsht a
where exists (select null
of empbooth b
where b.booth = 1
and b.empid = a.empid)
Maybe you are looking for
-
How do I activate my setting Do not not track?
I can't find anything that leads me to these many options that you claim to have on my mobile. Can you help me?
-
Aspire V 17 Nitro - function keys not working do not after Windows 7 installation
I just recently picked up an Aspire V 17 Nitro and immediately installed Windows 7 above. Everything works great so far but I noticed that the function keys do not work. Those where you hold down the "Fn" key and then do things like adjust volume. So
-
I had wireless access WAP54G for about two years, connected to a D-Link router which is connected to a SpeedStream 5260 DSL modem, he supported a desk and four laptops without any problem. The modem is old and starting to have problems of hosting an
-
How to remove the drivers for a device of a system completely.
Hello Product name: HP Pavilion dv6-6093ex Entertainment Notebook PC support. Product number: LM610EA #A2N I recently found a problem with my Bluetooth with a phone Samsung Galaxy Bluetooth pairing. I decided to uninstall all components from the prev
-
Account management works perfectly and my license runs out in August.Please, tell me what I can do or fix the bug again.Thank youFabrizio Pietrafesa