help sql two queries toload target table
create table table1
(code varchar2(10)
,mod_time date);
insert into table1 values('2533',to_date('31-JUL-2012', 'DD-MON-YY'));
insert into table1 values('2534',to_date('31-JUL-2012', 'DD-MON-YY'));
insert into table1 values('2535',to_date('01-SEP-2012', 'DD-MON-YY'));
create table table2
(code varchar2(10)
,ID NUMBER
,TYPE VARCHAR2(3)
,mod_time date);
insert into table2 values('2533',1,'AB',to_date('01-SEP-2012', 'DD-MON-YY'));
insert into table2 values('2534',1,'CD',to_date('01-SEP-2012', 'DD-MON-YY'));
create table table3
(ID NUMBER
,mod_time date);
insert into table3 values(1,to_date('01-SEP-2012', 'DD-MON-YY'));
insert into table3 values(2,to_date('01-SEP-2012', 'DD-MON-YY'));
create table target
(code varchar2(10)
,ID NUMBER
,TYPE VARCHAR2(3)
,table1_modtime date
,table2_modtime date
,table3_modtime date
,valid_till date
,valid_from date
drop table target
combine all the three tables where table1.mod_time<=31-jul-2012, table2.mod_time<=31-jul-2012,table3.mod_time<=31-jul-2012
initial load to target load should be get the information from all the tables modtime<=31-jul-2012
Need to have select query to get the below 1st load expected output
valid_till defaults to to_date('31-DEC-2030', 'DD-MON-YY')
valid_from defaults to to_date('01-01-1995', 'DD-MON-YY')
1st load expected output
code id type table1_modtime table2_modtime table3.modtime valid_from valid_till
2533 31-JUL-2012 01-01-1995 31-DEC-2030
2534 31-JUL-2012 01-01-1995 31-DEC-2030
-------------------------------------------------------------------------------------------------------
for the second charge. first get the query to get the values of all tablesmod_time > 31 July 2012.
If the code exists then update the existing record with valid_till in January 2, 2013 IE yesterday
and insert a new record with the new values and valid from date to January 3, 2013 IE today
--------------------2nd load expected output
code id type table1_modtime table2_modtime table3.modtime valid_from valid_till
2533 31-JUL-2012 01-01-1995 02-jan-2013 --updating old record valid-till to yesterday
2534 31-JUL-2012 01-01-1995 02-jan-2013 --updating old record valid-till to yesterday
2533 1 AB 31-JUL-2012 01-SEP-2012 01-SEP-2012 03-jan-2013 31-DEC-2030----updating old record valid-from to today
2534 1 CD 31-JUL-2012 01-SEP-2012 01-SEP-2012 03-jan-2013 31-DEC-2030--updating old record valid-from to today
2535 01-SEP-2012 01-01-1995 31-DEC-2030 --no record exist so insert new record in target table
--------------------------------------------------------------------------------------------------------
Published by: Daniel on January 3, 2013 17:01
Hello
Just check the data that you have inserted in the tables, because trying to join the table and put the date constraint its no return value
select T1.CODE as code ,t3.id as id ,t2.type as type ,T1.MOD_TIME as table1_modtime ,T2.MOD_TIME as table2_modtime ,T3.MOD_TIME as table3_modtime from table1 t1, table2 t2,table3 t3 where T1.CODE = t2.code and t2.id = t3.id
and t1.mod_time<=to_date('31-jul-2012', 'DD-MON-YY')
and t2.mod_time<=to_date('31-jul-2012', 'DD-MON-YY')
and t3.mod_time<=to_date('31-jul-2012', 'DD-MON-YY')
And that's because for code 2533 and 2534 in table1, the id entry in the table2 is 1. but the entry in table 3 for Id 1 is 01-SEP-2012, falling out of date. Please confirm on this data entry in table2.
Tags: Database
Similar Questions
-
Need help combining two SQLs similair in a single
DB version: 10 gr 2
I need to combine the following two queries into one query and return the following three columns
Processed, unprocessed Quantity1 Quantity2, Total cost of Uprocessed
Quantity1 untreated can be determined using
Quantity2 untreated can be determined usingselect t.ITEM, sum(t.QTY) from (select cd.ITEM_ID ITEM, cd.ACTL_QTY QTY from CONVEY_HDR ch, CURRENT_INVN cd, ALLOC_HDR ah where ........ UNION select sd.ITEM_ID ITEM, sd.INVN_QTY QTY from shp_dtl pd UNION Select item_id, inv_qty from another table GROUP BY..... ITEM SUM(T.QTY) ---------- ---------- 88JAT 25 000002395 1 300108396 27 000004397 7 73984290 15
Total fees unprocessed found using the sum of the quantities for a specific element by above two queries multiplied byselect t.ITEM, sum(t.QTY) from (select cd.ITEM_ID ITEM, cd.ACTL_QTY QTY from CONVEY_HDR ch, CURRENT_INVN cd, ALLOC_HDR ah ........... where rownum<6 group by t.ITEM order by t.ITEM; ITEM SUM(T.QTY) ---------- ---------- 189436171 2 009438837 160 000040685 16 000032410 18
ITEM_COST for this ARTICLE (which is in the table ITEM_DTL). For each element; ITEM_DTL.item_id = CARTON_dTL.carton_id
Unprocessed total cost = (unprocessed Quantity1 + Quantity2 unprocessed) * ITEM_DTL. ITEM_COST
Note: Unprocessed Quantity2 query looks very similair to the first SQL Union Quantity1 unprocessed, but ah. STAT_CODE < 90 for query Quantity2 unprocessed
Published by: user636669 on January 14, 2009 10:40
Published by: user636669 on January 14, 2009 10:57
Corrected typo
Published by: user636669 on January 14, 2009 19:07Hello
Put the two queries that you posted in subqueries. You can then use their result sets as if they were tables.
Do something like this:
WITH uq1 AS ( select t.ITEM, sum(t.QTY) AS total from (select cd.ITEM_ID ITEM, cd.ACTL_QTY QTY from CASE_HDR ch, CASE_DTL cd, ASN_HDR ah ... the rest of your first query goes here ) , uq2 AS ( select t.ITEM, sum(t.QTY) AS total from (select cd.ITEM_ID ITEM, cd.ACTL_QTY QTY from CASE_HDR ch, CASE_DTL cd, ASN_HDR ah ... the rest of your second query goes here ) SELECT uq1.item , uq1.total AS "Unprocessed Quantity1" , uq2.total AS "Unprocessed Quantity2" , (uq1.total + uq2.total) * dtl.item_cost AS "Total Uprocessed Cost" FROM uq1 JOIN uq2 ON uq1.item = uq2.item JOIN item_dtl dtl ON uq1.item = dtl.item;
If certain elements are in uq1 but not in uq2 (or more), then you will probably want to do outer joins.
I have no used tables, so I can't test it myself.
If you need assistance. then after a few examples from each data tables and the results desired from these data.Looks like you're doing the same join in each of your original queries.
You can add an another subquery that makes that join once and then use this subquery in uq1 and uq2 subqueries. -
We all hope you are doing well.
I have a business problem to implement in ODI 11 G. It's here. I'm trying to load a target table from two sources that have the same column names. But a source is to the file format and the other is in the Oracle database.
That's what I think I'll create two mappings in the same interface by using the Union between the sources. But I don't know how the interface would connect to different logical architecture to connect to two different sources.
Thank you
SM
You are on the right track, all in a single interface. Follow these steps
(1) pull model of your data in the designer of the source file and your table model target to the target pane.
(2) all relevant columns map
(3) in the source designer to create a new dataset and choose as the UNION join type (this will create a separate tab in the source designer pane)
(4) select the new dataset tab in the source designer pane and pull your source oracle table data model in the designer of the source. All columns that are relevant to the target card
(5) make sure that your staging location is set to a relational technology i.e. in this case the target would be an ideal candidate because it is where the ODI will organize the data from source two files and oracle and perform the UNION before loading to the target
If you want to watch some pretty screenshots showing the steps above, take a look at http://odiexperts.com/11g-oracle-data-integrator-part-611g-union-minus-intersect/
-
Help to combine the two queries with dependencies
Combining two queries with dependencies:First ask: Returns USER_ID that has a type of access to a table with the OWNER (I also shoot the TLA of the USER_ID standard: ' of TLA #)Select distinct SUBSTR (DBA_USERS. Username, 2, 3) AS TLA
DBA_USERS. Username USED_ID
DBA_TAB_PRIVS. Owner OWNER
from DBA_USERS
DBA_ROLE_PRIVS
DBA_TAB_PRIVS
where DBA_USERS. Username = DBA_ROLE_PRIVS. Dealer
and DBA_USERS.default_tablespace not in ('SYSTEM', "SYSAUX")
and DBA_USERS. Username like would be %'
and DBA_ROLE_PRIVS. Granted_role = DBA_TAB_PRIVS. Dealer
and SUBSTR (DBA_USERS. Username, 2, 3) <>DBA_TAB_PRIVS. Owner
;
Example of results (red font used in the last citation):TLA USED_ID OWNER
--- ------------------------------ ------------------------------
DGTX999 GTX GRR
DGTX999 GTX ABG
DGTX999 GTX HTC
FWS DFWS999 GRR
OCN DOCN999 GRR
RHR DRHR999 DAS
ETM DETM999 DAS
FWS DFWS995 DAS
CD DCDS999 DAS
ABE DABE999 DAS
Second request: matches the USER name (same standards as above) and MACHINES (filter PC connections) and the number of connections made ofSelect DBA_USERS. Username
DBA_HIST_ACTIVE_SESS_HISTORY. Machine
COUNT (*) AS CONN_COUNT
of DBA_HIST_ACTIVE_SESS_HISTORY
DBA_USERS
where DBA_HIST_ACTIVE_SESS_HISTORY. User_id = DBA_USERS. User_id
and DBA_USERS. Username like would be %'
and DBA_HIST_ACTIVE_SESS_HISTORY. Machine not as "WINAD%\%-%".
Group of DBA_USERS. Username
DBA_HIST_ACTIVE_SESS_HISTORY. Machine
order by 1
3 desc;
Example of results (red font used in the last citation):MACHINE CONN_COUNT USERNAME
--------------- ------------------------- ----------
DFWS999 home13e0 7557
DGAM800 vu1246 37
DGAM999 vu1246 2558
DABE999 back18cb 4639
DINL888 home162f 84
DFWS999 WINDAD\OMHQ58BF 178
DCDS999 back18cb 788
DGTX999 home18c8 7
DGTX999 home13d3 62
DOCN999 vu1261 44
DFWS999 back1976 3
DCDS999 home18c8 173
DGTX999 home19c9 13
What I'd like to have (just made two first USER_IDs from the first query) (COL duplicated for each separate owner 1-4). So 3 machines and 3 owners would result in 9 lines (I could reorganize the collar and use a 'pause'):
TLA USED_ID MACHINE CONN_COUNT OWNER
--- ------------------------------ ------------------------- ---------- ------------------------------
GTX DGTX999 home13d3 62 GRR
Home18c8 GTX DGTX999 7 GRR
DGTX999 GTX home19c9 GRR 6
GTX DGTX999 home13d3 62 ABG
DGTX999 GTX home18c8 ABG 7
DGTX999 GTX home19c9 6 GBS
GTX DGTX999 home13d3 62 CTH
DGTX999 GTX HTC 7 home18c8
DGTX999 GTX home19c9 6 HTC
FWS DFWS999 home13e0 7557 GRR
FWS DFWS999 WINDAD\OMHQ58BF 178 GRR
FWS DFWS999 back1976 GRR 3
So it would be logically read: TLA as USER_ID of MACHINE, CONN_COUNT consultation times: OWNER information.Thought as only those with the necessary values. Just try this and let me know in the case of all conflicts in the output.
WITH T1 AS)
Select distinct SUBSTR (DBA_USERS. Username, 2, 3) AS TLA
DBA_USERS. Username USED_ID
DBA_TAB_PRIVS. Owner OWNER
ROWNUM RN
from DBA_USERS
DBA_ROLE_PRIVS
DBA_TAB_PRIVS
where DBA_USERS. Username = DBA_ROLE_PRIVS. Dealer
and DBA_USERS.default_tablespace not in ('SYSTEM', "SYSAUX")
and DBA_USERS. Username like would be %'
and DBA_ROLE_PRIVS. Granted_role = DBA_TAB_PRIVS. Dealer
and SUBSTR (DBA_USERS. Username, 2, 3) <> DBA_TAB_PRIVS. Owner),
() AS T2
Select DBA_USERS. Username
DBA_HIST_ACTIVE_SESS_HISTORY. Machine
COUNT (*) AS CONN_COUNT
of DBA_HIST_ACTIVE_SESS_HISTORY
DBA_USERS
where DBA_HIST_ACTIVE_SESS_HISTORY. User_id = DBA_USERS. User_id
and DBA_USERS. Username like would be %'
and DBA_HIST_ACTIVE_SESS_HISTORY. Machine not as "WINAD%\%-%".
Group of DBA_USERS. Username
DBA_HIST_ACTIVE_SESS_HISTORY. Machine
order by 1
3 desc)
SELECT T1. TLA
, T1. USED_ID
, T2. MACHINE
, T2. CONN_COUNT
, T1. OWNER
FROM T1
T2
WHERE T1. USED_ID = T2. USER NAME;
-
delete all, then insert into the target table, two steps in one transaction?
Hello
We have the following two steps in one ODI package, it will be managed in a single transaction?
procedure step 1): remove all of the target table.
interface in step 2): insert data in the source table in the target table.
our problem is that step 2 can take some minutes, and then the target table can temporary unusable for end users who try to access it, I'm good?
Kind regards
MarijoHello
It can be managed in a single transaction by selecting IKM as the Append and TRUNCATE/DELETEALL Option command in the FLOW of an interface tab.
Thanxs
Malezieux -
How to combine the two queries into a single
Hi gurus,
SQL > select * from v version $;
BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.4.0 - Production 64-bit
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
AMT for Linux: release 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL >
I have following two queries. How can I convert these two queries into one with the same result?
1ST QUARTER
SELECT id, $vdate, SupplierName, venddate, vid
THE SELLER
WHERE processid = 32
AND venddate is null
AND vid to (select vid from view_vid where type = 'PDX')
AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = 55)
AND (id, $vdate) in (select id, vidate from market_data where marketed_date is null)
AND id not in (select id from location)
Q2
SELECT id, $vdate, SupplierName, venddate, vid
THE SELLER
WHERE processid = 20
AND venddate is null
AND vid to (select vid from view_vid where type = 'PBX')
AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = 40)
AND (id, $vdate) in (select id, vidate from market_data where region_date is null)
AND id not in (select id from location)
I can the UNION queries these two, but is there some way I can write a single query that gives me the same result as above two queries?
Any help would be much appreciated
Thanks in advance
Sorry, it lack
SELECT id, $vdate, SupplierName, venddate, vid
THE SELLER
ProcessID WHERE in (32.20)
AND venddate is null
AND vid to (select vid from view_vid where type = case when processid = 32
then "PDX".
else "PBX".
end)
AND (id, $vdate) not in (select id, $vdate from vkfl_is where task_id = case when processid = 32
then 55
40 else
end)
AND (id, $vdate) in (select id, vidate from market_data cases where processid = 32)
then marketed_date
of other region_date
end to the null value
)
AND id not in (select id from location)
Concerning
Etbin
-
Any difference between the two queries
Hello
Could someone please help me to see if the following two queries return different results?
Thank you
Query A
SELECT A.BATCH_NO,
A.BU_CODE,
SUM (A.AMOUNT) AMOUNT
FROM TABLE_A HAS
WHERE A.BU_CODE = 20
AND G_DATE BETWEEN TO_DATE (JANUARY 31, 2013 ',' MON-DD-YYYY "")
AND TO_DATE (MARCH 31, 2013 ',' MON-DD-YYYY "")
--
AND A.BATCH_NO IN (SELECT BATCH_NO
TABLE_A B1
WHERE B1. BATCH_NO = A.BATCH_NO
AND B1. BU_CODE = A.BU_CODE
AND B1. ' CODE_P = ' 06-01-01-000.
AND B1. FROM_FLAG = 'FROM '.
)
AND A.BATCH_NO IN (SELECT BATCH_NO
FROM TABLE_A B
WHERE B.BATCH_NO = A.BATCH_NO
AND B.BU_CODE = A.BU_CODE
AND B1.ORG = '10'
)
A.BATCH_NO GROUP,
A.BU_CODE
;
Query B
SELECT A.BATCH_NO,
A.BU_CODE,
SUM (A.AMOUNT) AMOUNT
FROM TABLE_A HAS
WHERE A.BU_CODE = 20
AND G_DATE BETWEEN TO_DATE (JANUARY 31, 2013 ',' MON-DD-YYYY "")
AND TO_DATE (MARCH 31, 2013 ',' MON-DD-YYYY "")
--
AND A.BATCH_NO IN (SELECT BATCH_NO
TABLE_A B1
WHERE B1. BATCH_NO = A.BATCH_NO
AND B1. BU_CODE = A.BU_CODE
AND B1. ' CODE_P = ' 06-01-01-000.
AND B1. FROM_FLAG = 'FROM '.
AND B1.ORG = '10'
)
A.BATCH_NO GROUP,
A.BU_CODE
;
Hello
These 2 requests are not the same. Depending on your data, query A, can select more lines as searching for B.
I do not have access to your table, so I'll give an example of using the table scott.emp.
The following 2 queries look like your 2 questions:
SELECT deptno - query A
work
sal
FROM scott.emp m
WHERE deptno IN ((in English only)
SELECT sj.deptno
FROM scott.emp sj
WHERE sj.deptno = m.deptno
AND sj.job = 'CLERK '.
)
AND (IN) deptno
SELECT ss.deptno
FROM scott.emp ss
WHERE ss.deptno = m.deptno
AND ss.sal > 1200
)
;SELECT deptno - query B
work
sal
FROM scott.emp m
WHERE deptno IN ((in English only)
SELECT s.deptno
FROM scott.emp s
WHERE s.deptno = m.deptno
AND s.job = 'CLERK '.
AND s.sal > 1200
)
;The results of A query are all 14 rows in the table, but query B produces only 3 lines of deptno = 10.
Query A looking for departments who have committed and the departments that have sal > 1200. If a line in the Department has job = 'CLERK' (regardless of the sal), and another line was sal > 1200 (regardless of the work), while the Department meets both criteria.
Query B is looking for federal departments who have committed that sal is over 1200. Two criteria must be met on the same line.
-
Create a target table by using the model of the ODI
Hi all
I am new to ODI. I'm try export table RDBMS for source RDBMS table at target.
If we create the structure of the target in the trg schema table or we can create using the model fit obi by selecting new data store.
Owb loading target tables is created and the data will be loaded.
Pls help me about this.
Thanks in advance.Hello
You can create it in the two ways.if you create using ODI data store, you must select Create table option target in flow during loading of the target. -
MERGE TWO QUERIES...
Hi all
I have two queries like this...
I want to have a single query of the two tables satisfying condition where that show all RELATIONSHIP, FILED_NAME, P2. ATTRIBUTE, P3. ATTRIBUTE, DESCRIPTION of the AREA, the two SOURCE tables P3 AND P2.
Appreciate your help.
Thank you/kumar
Published by: kumar73 on May 28, 2010 09:49Hope you have understood my requirement.
Ah, I see now that I misread your question (it must be a 'weekend-thing' ;)).
Try something like this:
select p3.relation , p3.field_name , p2.attribute , p3.attribute , p3.value_description , p3.source from ( select relation, field_name, attribute, field_description, source from p3i2009q2_variable_info p3 where relation not in ('CHAI', 'ITAB', 'ITB2', 'ITB3', 'MINI', 'NOTE', 'MINC', 'FINI', 'FTIM', 'FWTG', 'FMLY', 'FMIS', 'FSUM', 'MEMB', 'FINC', 'FASO') and (substr(field_name, -2) in ('X1', 'X2', 'X3', 'X4', 'X5', 'X0', 'XA', 'XB', 'XM', 'XP', 'CM', 'MT') or substr(field_name, -1) in ('X') or substr(field_name, 1) in ('J')) and (attribute like 'NUM%' or attribute = '-') ) p3 , ( select relation, field_name, attribute, field_description, source from p2i2009m04_variable_info p2 where relation not in ('CHAI', 'ITAB', 'ITB2', 'ITB3', 'MINI', 'NOTE', 'MINC', 'FINI', 'FTIM', 'FWTG', 'FMLY', 'FMIS', 'FSUM', 'MEMB', 'FINC', 'FASO') and (substr(field_name, -2) in ('X1', 'X2', 'X3', 'X4', 'X5', 'X0', 'XA', 'XB', 'XM', 'XP', 'CM', 'MT') or substr(field_name, -1) in ('X') or substr(field_name, 1) in ('J')) and (attribute like 'NUM%' or attribute = '-') ) p2 where p3.relation = p2.relation order by relation;
You may need to adjust my untested example, for example you might need an outer join and/or add predicates more as you wish.
-
Why this two queries are not same
Hi all
Can you please explain this fundamental thing. Why this two queries are different. (10.2.0.3 Solaris Sparc 64)
create table x1(a1 varchar2(10),a2 number, a3 varchar2(10)); create table x2(b1 varchar2(10),b2 number, b3 varchar2(10)); insert into x1 values('X101',1,'XX1'); insert into x1 values('X101',1,'XX1'); insert into x1 values('X102',1,'XX2'); insert into x1 values('X103',2,'XX3'); insert into x1 values('X104',2,'XX4'); insert into x1 values('X105',3,'XX5'); commit; insert into x2 values('X101',1,'X21'); insert into x2 values('X101',1,'X21'); insert into x2 values('X102',1,'X22'); insert into x2 values('X103',2,'X23'); insert into x2 values('X104',2,'X24'); commit; WITH xx AS (select b1,b2 from x2 where b1 IS NULL) select x1.* from x1 , xx where x1.a1 = xx.b1(+) and x1.a2 = xx.b2(+) ; A1 A2 A3 ---------- ---------- ---------- X105 3 XX5 X104 2 XX4 X102 1 XX2 X103 2 XX3 X101 1 XX1 X101 1 XX1 6 rows selected select x1.* from x1, x2 where x1.a1 = x2.b1(+) and x1.a2 = x2.b2(+) and x2.b1 IS NULL; A1 A2 A3 ---------- ---------- ---------- X105 3 XX5 select b1,b2 from x2 where b1 IS NULL; B1 B2 ---------- ----------
Thank you!
NA not (sentence of) think of this.
+ (it's one of those things that I really need of don't forget do not forget ;)) +)hoek&XE> select x1.* 2 from x1 3 where not exists ( select null 4 from x2 5 where x1.a1 = x2.b1 6 and x1.a2 = x2.b2 7 ); A1 A2 A3 ---------- ---------- ---------- X105 3 XX5 1 rij is geselecteerd. Uitvoeringspan ---------------------------------------------------------- Plan hash value: 816925353 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 5 | 100 | 5 (20)| 00:00:01 | |* 1 | HASH JOIN ANTI | | 5 | 100 | 5 (20)| 00:00:01 | | 2 | TABLE ACCESS FULL| X1 | 6 | 72 | 2 (0)| 00:00:01 | | 3 | TABLE ACCESS FULL| X2 | 5 | 40 | 2 (0)| 00:00:01 | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("X1"."A1"="X2"."B1" AND "X1"."A2"="X2"."B2") Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6 consistent gets 0 physical reads 0 redo size 518 bytes sent via SQL*Net to client 384 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed
-
Try to combine the two queries
I have two queries of tables in which I combine and summarize the results in a single value. Could someone let me know what it is that im missing here? Thank you
Deanna
Output current:
SUM
5
10
The output I want to see:
SUM
15
My paintings:
TABLE 'CHART '.
CASE_NUMBER - VARCHAR2
PER_INV_FATALITIES - NUMBER (5.0)
ASSIGNEDDATE_CHART - DATE
TABLE "VEHICLES".
CASE_NUMBER - VARCHAR2
VEHICLE_FATALITY #-NUMBER (5.0)
Current SQL query:
SELECT SUM(ct) FROM ( SELECT SUM(vehicle_fatality#) ct FROM vehicles inner join chart on vehicles.case_number=chart.case_number WHERE vehicle_fatality#>=1 AND ASSIGNEDDATE_CHART BETWEEN TO_CHAR(TRUNC(SYSDATE,'RR'),'DD/MON/RR')AND SYSDATE) union all SELECT SUM(ct) FROM ( SELECT SUM(per_inv_fatalities) ct FROM chart WHERE PER_INV_FATALITIES>=1 AND ASSIGNEDDATE_CHART BETWEEN TO_CHAR(TRUNC(SYSDATE,'RR'),'DD/MON/RR')AND SYSDATE);
Hello
Instead of:
SELECT SUM (ct) FROM (query_a) UNION ALL SELECT SUM (ct) FROM (query_b) ;
do
SELECT SUM (ct) FROM ( query_a UNION ALL query_b ) ;
SUM without GROUP BY will produce a line.
If you do a UNION ALL of two queries of this type operation, you will get two rows.
The UNION ALL first, then make a single SUM on the combined results. -
compare the fields of two queries
I need to compare the fields of two queries.
I went through many articles to asktom help operator less. but I'm not convinced by this method.
Comaprisons are for about 10 fields.
So I'm planing to do using sliders and nested loops. performance can be a problem.
Please give your suggestions or solutions.OK, using the data you provided, I get this:
with map_test_fac as (select 100 idid, 789 ifid, 300 edid, 741 efid from dual union all select 100 idid, 123 ifid, 300 edid, 963 efid from dual union all select 100 idid, 456 ifid, 300 edid, 258 efid from dual), test_fac as (select 741 facid, 'ETY' type, 'EUR' ccy, 'Ext' src, 300 did from dual union all select 789 facid, 'WE' type, 'EUR' ccy, 'Int' src, 100 did from dual union all select 123 facid, 'VPR' type, 'EUR' ccy, 'Int' src, 100 did from dual union all select 456 facid, 'ETY' type, 'USD' ccy, 'Int' src, 100 did from dual union all select 963 facid, 'WE' type, 'EUR' ccy, 'Ext' src, 300 did from dual union all select 258 facid, 'VPR' type, 'EUR' ccy, 'Ext' src, 300 did from dual) -- end of mimicking your data: USE SQL below: select tfi.facid int_facid, tfi.type int_type, tfi.ccy int_ccy, tfi.src int_src, tfi.did int_did, tfe.facid ext_facid, tfe.type ext_type, tfe.ccy ext_ccy, tfe.src ext_src, tfe.did ext_did from test_fac tfi, test_fac tfe, map_test_fac mtf where mtf.ifid = tfi.facid and mtf.efid = tfe.facid and mtf.idid = tfi.did and mtf.edid = tfe.did and (tfi.type != tfe.type or tfi.ccy != tfe.ccy) INT_FACID INT INT INT INT_DID EXT_FACID EXT EXT EXT EXT_DID ---------- --- --- --- ---------- ---------- --- --- --- ---------- 789 WE EUR Int 100 741 ETY EUR Ext 300 123 VPR EUR Int 100 963 WE EUR Ext 300 456 ETY USD Int 100 258 VPR EUR Ext 300
However, I think that your mapping data is incorrect, so with keys of information:
with map_test_fac as (select 100 idid, 789 ifid, 300 edid, 963 efid from dual union all select 100 idid, 123 ifid, 300 edid, 258 efid from dual union all select 100 idid, 456 ifid, 300 edid, 741 efid from dual), test_fac as (select 741 facid, 'ETY' type, 'EUR' ccy, 'Ext' src, 300 did from dual union all select 789 facid, 'WE' type, 'EUR' ccy, 'Int' src, 100 did from dual union all select 123 facid, 'VPR' type, 'EUR' ccy, 'Int' src, 100 did from dual union all select 456 facid, 'ETY' type, 'USD' ccy, 'Int' src, 100 did from dual union all select 963 facid, 'WE' type, 'EUR' ccy, 'Ext' src, 300 did from dual union all select 258 facid, 'VPR' type, 'EUR' ccy, 'Ext' src, 300 did from dual) -- end of mimicking your data: USE SQL below: select tfi.facid int_facid, tfi.type int_type, tfi.ccy int_ccy, tfi.src int_src, tfi.did int_did, tfe.facid ext_facid, tfe.type ext_type, tfe.ccy ext_ccy, tfe.src ext_src, tfe.did ext_did from test_fac tfi, test_fac tfe, map_test_fac mtf where mtf.ifid = tfi.facid and mtf.efid = tfe.facid and mtf.idid = tfi.did and mtf.edid = tfe.did and (tfi.type != tfe.type or tfi.ccy != tfe.ccy) INT_FACID INT INT INT INT_DID EXT_FACID EXT EXT EXT EXT_DID ---------- --- --- --- ---------- ---------- --- --- --- ---------- 456 ETY USD Int 100 741 ETY EUR Ext 300
That's more like what you're looking for?
-
ODI 12 c: IKM for differential insert and update with a sequence in the target table
Hello
I have a map where I fill in a column of my target table using a database sequence. Now my mapping is supposed to load the target gradually table. So I need a revenge for update and incremental insert. Now with this differential IKM it compares all the columns to match all colmuns line to understand, it should be an insert or update. Now, the following code shows that when the ROW_WID is loaded with a sequence of database.
If NOT EXISTS
(select 1 from W_LOV_D T
where T.ROW_WID = S.ROW_WID
and ((T.CREATED_BY = S.CREATED_BY) or (T.CREATED_BY IS NULL and S.CREATED_BY IS NULL)) and
....
....
< the rest of the comparison of columns >
)
So when running ODI returns following error
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "S". "" ROW_WID ": invalid identifier
Please suggest if there is no other IKM I should use or if there is another way around it without changing the code IKM...
Hi Marc,
Thanks for your reply.
I had solved it. The incremental update process inserts all rows from the source table to I$ table that exists in the target table. It does so by the where sql such as mentioned in my questions as
WHERE THERE is NOT (
. COLUMNS = -
The logged data is not loaded in the target table in cdc-compatible?
Hello
I tried with cdc-simple concept on single table.
I had loaded, journaled table (only changed records) inserted in the simple target in cdc table. Its working fine.
When I work on cdc-consistent and logged data are not loaded in the target table
For this, I used the data model, it has 3 data stores. log the without option of data, its works very well.
When I am trying to load tables logged in the target table in interface, its running fine.
To do this, I chose "logged data only.
Although I have not changed the records in the target table. target table is empty after the executed insterface.
I chose the real option of insertion in ikm. But the logged data that is not inserted in the target table.
Please help me.
Thankin advacnce,
A.Kavya.
Hello
You must EXPAND WINDOW and LOCK SUBSCRIBERS before consuming the CDC data:
http://docs.Oracle.com/CD/E14571_01/integrate.1111/e12643/data_capture.htm#ODIDG283
Subsequently, you unlock Subscriber and purge the log.
Better to put a package to automate the whole thing.
-
Failed to truncate the target table while programming the interface in ODI
Hi Expertise,
I developed a scenario in an interface, where I planned keeping the option Truncate as false, right there the data is been going to target without any problems, but when I changed the status of truncate to TRUE, the interface is been run, but the array is not get truncated, rather the data's been loading again to target. (when running manually, the target table is been truncated perfectly) but not in programming.
Can someone help me in this problem.
Thank you
Shakur.
Have you regenerate the scenario in question since you changed the option Truncate. If you have not the regular job must still run the old code
Maybe you are looking for
-
Portege R100 - CPU up to 100% usage during execution of foobar2000
Hello! Everyone knows about this problem?My Portege R100 after installing the new copy of Windows XP and directly after the installation of the display driver, Trident (reboot) bizarre behavior. Welcome screen goes white on the lower part (when the f
-
HP Pavilion 15-ab522TX: AccelerometerSt.exe (0xc000007b) error at startup
This (0xc000007b) error started to appear after updating Windows 10 after starting. Because of this error, my laptop product sounds weird when I press buttons as rshift, the top button windows tab. The taskbar are also became unresponsive. Help, plea
-
That means "lyics on Laurence software?
I was about to uninstall a program that says words on Laurence software that is Moved from feedback Original title: what does lyics on average
-
Replacement of the motherboard of Dell Inspiron 530
Hello guys,. The motherboard in my Dell Inspiron 530 goes wrong. I am currently looking for a direct replacement and want to reuse the case. Will be something like this work? Thank you!
-
BlackBerry Q10 I need help with my BlackBerry
What is the point of a BlackBerry backup if your phone will not work after? My BlackBerry broke and I got a new same model one and all. I did not put in place the new BlackBerry so I had a backup and I restored the backup to the phone. All installed