Reg: query logic.
Hi Experts,
I have a requirement of query which am not able to achieve correctly-
2 tables like this:
WITH t1 AS)
SELECT the 1 id, cm_dt of TO_DATE('04.04.2014','dd.mm.yyyy') OF double UNION ALL
SELECT 2 id, TO_DATE('01.11.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL
SELECT 2 id, TO_DATE('29.09.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL
Select 3 id, to_date('17.05.2013','dd.mm.yyyy') cm_dt of the double
)
t2 AS)
SELECT the 1 id, TO_DATE('04.05.2014','dd.mm.yyyy') fh_dt, ov 'b', 'a' double UNION ALL nv
SELECT 1 id, TO_DATE('21.05.2014','dd.mm.yyyy'), 'y', 'x' FROM dual UNION ALL
SELECT 2 id, TO_DATE('01.10.2013','dd.mm.yyyy'), 'r', 'e' FROM dual UNION ALL
SELECT the id 2, TO_DATE('15.10.2013','dd.mm.yyyy'), 'x', 'q' FROM dual UNION ALL
SELECT 2 id, TO_DATE('29.03.2014','dd.mm.yyyy'), 'f', 'b' FROM dual
)
My requirement is :
Check - 1
For each ID of "t1", need to check in 't2' If a record exists. If the 'id' doesn't exist, you need to select another table called "table_y". Here, T1.ID = 3
Check the box - 2
If the ID exists, for each 'id' and T1. CM_DT - is any record in T2 where (T1.id = T2.id and T1. CM_DT < T2. Take FH_DT) then the OV (old value) of the last record.
Otherwise, if no such folder i.e. all have T1. CM_DT > T2. FH_DT - take NV (new value) of the first record.
Expected results :
1 04.04.2014 b
2 01.11.2013 q
2 29.09.2013 r
3 17.05.2013 < some value from another table >
My try and try again...
WITH t1 AS)
SELECT the 1 id, cm_dt of TO_DATE('04.04.2014','dd.mm.yyyy') OF double UNION ALL
SELECT 2 id, TO_DATE('01.11.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL
SELECT 2 id, TO_DATE('29.09.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL
Select 3 id, to_date('17.05.2013','dd.mm.yyyy') cm_dt of the double
)
t2 AS)
SELECT the 1 id, TO_DATE('04.05.2014','dd.mm.yyyy') fh_dt, ov 'b', 'a' double UNION ALL nv
SELECT 1 id, TO_DATE('21.05.2014','dd.mm.yyyy'), 'y', 'x' FROM dual UNION ALL
SELECT 2 id, TO_DATE('01.10.2013','dd.mm.yyyy'), 'r', 'e' FROM dual UNION ALL
SELECT the id 2, TO_DATE('15.10.2013','dd.mm.yyyy'), 'x', 'q' FROM dual UNION ALL
SELECT 2 id, TO_DATE('29.03.2014','dd.mm.yyyy'), 'f', 'b' FROM dual
)
------
x AS
(SELECT
T1.ID, t1.cm_dt, t2.fh_dt, nv, ov,
ROW_NUMBER() over (PARTITION BY t2.id ORDER BY fh_dt asc) Clotilde,
MIN (T2.fh_dt) on min_dt (PARTITION BY t2.id),
Max (T2.fh_dt) on max_dt (PARTITION BY t2.id)
T1 LEFT JOIN t2 ON (t1.id = t2.id)
)
--------
SELECT distinct
x.ID, x.cm_dt, x.fh_dt,
(CASE WHEN cm_dt < = min_dt THEN)
(SELECT t2.ov FROM t2 WHERE t2.id = AND t2.fh_dt x.id = x.min_dt)
ON THE OTHER
(SELECT t2.ov FROM t2 WHERE t2.id = AND t2.fh_dt x.id = x.min_dt)
Chk1 END)
X
ORDER BY id, cm_dt
Please give some guidance. Help much appreciated.
-Nordine
(on Oracle 11.2.0.3.0)
I think it's something like what you are looking for (if you had provided details of the 'other' table you want to get the values of, then I could have tried integrate this logic in this query, rather than do something using the double table!):
WITH t1 AS (SELECT 1 id, TO_DATE('04.04.2014','dd.mm.yyyy') cm_dt FROM dual UNION ALL SELECT 2 id, TO_DATE('01.11.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL SELECT 2 id, TO_DATE('29.09.2013','dd.mm.yyyy') cm_dt FROM dual UNION ALL select 3 id, to_date('17.05.2013','dd.mm.yyyy') cm_dt from dual), t2 AS (SELECT 1 id, TO_DATE('04.05.2014','dd.mm.yyyy') fh_dt, 'a' nv,'b' ov FROM dual UNION ALL SELECT 1 id, TO_DATE('21.05.2014','dd.mm.yyyy') , 'x','y' FROM dual UNION ALL SELECT 2 id, TO_DATE('01.10.2013','dd.mm.yyyy') , 'e','r' FROM dual UNION ALL SELECT 2 id, TO_DATE('15.10.2013','dd.mm.yyyy') , 'q','x' FROM dual UNION ALL SELECT 2 id, TO_DATE('29.03.2014','dd.mm.yyyy') , 'b','f' FROM dual), res as (select t1.id, t1.cm_dt, t2.fh_dt, t2.nv, t2.ov, min(case when t2.fh_dt > t1.cm_dt then t2.fh_dt end) over (partition by t2.id, t1.cm_dt) min_t2_fh_dt_past_cm_dt, max(case when t2.fh_dt < t1.cm_dt then t2.fh_dt end) over (partition by t2.id, t1.cm_dt) max_t2_fh_dt_pre_cm_dt, coalesce(max(case when t2.fh_dt < t1.cm_dt then t2.fh_dt end) over (partition by t2.id, t1.cm_dt), min(case when t2.fh_dt > t1.cm_dt then t2.fh_dt end) over (partition by t2.id, t1.cm_dt)) comparison_dt from t1, t2 where t1.id = t2.id (+)) select id, cm_dt, case when comparison_dt is null then (select 'zzz' from dual) when comparison_dt > cm_dt then ov when comparison_dt < cm_dt then nv end replacement_value from res where comparison_dt is null or comparison_dt = fh_dt; ID CM_DT REPLACEMENT_VALUE ---------- ---------- -------------------------------- 1 04/04/2014 b 2 29/09/2013 r 2 01/11/2013 q 3 17/05/2013 zzz
Tags: Database
Similar Questions
-
How can I fix this. REG QUERY "HKLM\SOFTWARE\Microsoft.
HELP... Can someone please tell me what this means and how can I fix. REG QUERY 'HKLM\SOFTWARE\Microsoft NT\CurrentVersion\AppcompatFlags\UpgrapeExperienceIndicators' / v UpgEx: finderstr UpgEx ERROR: the system was unable to find the specified registry or the value key.
How does this relate to the features of Windows Update (or recovery)?
Did you mean "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\ExperienceIndicatorsUpgrade... » ?
Is this a computer Win7 Pro or Ultimate?
Is this the same computer (not the same problem) in one or two of these previous discussions of yours?...
-
Hello
I'm trying to use Reg Query to review the contents of a registry key. More precisely
- HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify
I just want to know what are the subkeys. I expect to be
- IconStreams and
PastIconsStream
Since they are both of type reg_binary, when I do this query I have also all binary data as well, make very large output.Is there a way to simply retrieve/request which is in the field/column name and not the data column/field? I tried the /k options and /v who gave me errors, which I interpreted in the sense I was their use either wrong or they are not used in this instance.
There is not a lot of examples out there and most of repeat them what you find when you use /?.
Thank you.
Hello
The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums.
http://social.msdn.Microsoft.com/forums/en-us/windowsgeneraldevelopmentissues
-
Hello
I'm trying to use Reg Query to review the contents of a registry key. More precisely
- HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify
I just want to know what are the subkeys. I expect to be
- IconStreams and
PastIconsStream
Since they are both of type reg_binary, when I do this query I have also all binary data as well, make very large output.
Is there a way to simply retrieve/request which is in the field/column name and not the column/field data ? I tried the /k options and /v who gave me errors, which I interpreted in the sense I was their use either wrong or they are not used in this instance.
There is not a lot of examples out there and most of repeat them what you find when you use /?.
Thank you.
Hello
The question you posted would be better suited in the MSDN Forums. I would recommend posting your query in the MSDN Forums.
http://social.msdn.Microsoft.com/forums/en-us/windowsgeneraldevelopmentissues
-
Not able to understand the query logic
Hello
Please, help me to understand the logic of the query below.
I have an emp table having 2 emp_id and mgr_id column.
data from table.
emp_id mgr_id
1
2 2
3 3
4 5
5
6 5
6 of 7
6 of 8
9 7
I run the query below...
Select * from emp where emp_id not in (select mgr_id from emp);
Query giving no line.
I need to know the logic of the query.
Thank you
HIMSBecause there are some NULL values in the column so 'IN' mgr_id would fail to compare values such as 1,4,8,9 which are not there in mgr_id with these NULL values.
Use NVL like below to get the desired results...
with t as ( select 1 emp_id, null mgr_id from dual union all select 2,2 from dual union all select 3,3 from dual union all select 4,5 from dual union all select 5,null from dual union all select 6,5 from dual union all select 7,6 from dual union all select 8,6 from dual union all select 9,7 from dual ) SELECT * FROM t WHERE emp_id NOT IN (SELECT nvl(mgr_id,0) from t );
Concerning
Arun -
I need to archive records based on multiple rules. I got this resolved with the exception of a rule. Here's the scenario.
With the help of Oracle database 11 g 2.
create table tab ( id number primary key , status_id number , supplier_id number , supplier_type_id number , dt_eff_from date ) / insert into tab values(10,2,234000,84,sysdate-10) / insert into tab values(15,2,234000,84,sysdate-15) / insert into tab values(20,1,234000,84,sysdate-20) / insert into tab values(30,1,234000,84,sysdate-30) / insert into tab values(40,2,234000,84,sysdate-40) / insert into tab values(50,1,234000,84,sysdate-50) / insert into tab values(60,2,999999,25,sysdate-10) / insert into tab values(70,2,999999,25,sysdate-15) / insert into tab values(80,2,999999,25,sysdate-20) / insert into tab values(90,1,777777,33,sysdate-10) / insert into tab values(100,2,777777,33,sysdate-20) / insert into tab values(110,2,777777,33,sysdate-30) / commit ; ID STATUS_ID SUPPLIER_ID SUPPLIER_TYPE_ID DT_EFF_FROM ---------- ---------- ----------- ---------------- -------------------- 10 2 234000 84 17-APR-2015 15 2 234000 84 12-APR-2015 20 1 234000 84 07-APR-2015 30 1 234000 84 28-MAR-2015 40 2 234000 84 18-MAR-2015 50 1 234000 84 08-MAR-2015 60 2 999999 25 17-APR-2015 70 2 999999 25 12-APR-2015 80 2 999999 25 07-APR-2015 90 1 777777 33 17-APR-2015 100 2 777777 33 07-APR-2015 110 2 777777 33 28-MAR-2015
Batch: 1 approved =, 2 = rejected
Records are analyzed on the basis supplier_id + supplier_type_id
Rule 1: When batch = 2 dt_eff_from is greater than dt_eff_from for records with batch = 1
We need to keep (not archives) the most recent registration rejected
We just need to keep the most recent rejected (batch = 2) record when there is none
approved (batch = 1) record.
When batch = 1 has a greater dt_eff_from than the batch = 2 records, then we can archive
all the batch = 2 files, but we have to keep (not archives) the batch = 1 sheet
select id from tab -- initially all records are candidates to be archived MINUS select id from tab where <logic for rule 1 goes here> ID --- 15 20 30 40 50 70 80 100 110
Based on rule 1, all the files get archived except ID = 10 ID = 60 and ID = 90
Any thoughts?
SELECT * FROM)
SELECT T.*
MAX (batch) OVER (PARTITION BY SUPPLIER_ID, SUPPLIER_TYPE_ID) last_status_id KEEP(DENSE_RANK LAST ORDER BY DT_EFF_FROM,ID)
ROW_NUMBER() over (PARTITION OF SUPPLIER_ID, SUPPLIER_TYPE_ID ORDER BY DT_EFF_FROM DESC, ID DESC) rn
T tab
)
WHERE (last_status_id = 2 AND rn = 1) OR (last_status_id = 1 AND batch = 1);
-
Dear all,
I have two tables
TABLE A (A_DATE, COLA1, COLA2)
TABLE B (B_DATE)
A_DATE = B_DATE
Examples of tables:
TABLE A (11 selected lines)
A_DATE COLA1 COLA2 03/01/2013 54 VAL76 04/01/2013 11 VAL78 04/01/2013 11 VAL22 04/01/2013 74 VAL22 04/02/2013 15 VAL45 04/02/2013 11 VAL22 04/03/2013 44 VAL22 04/03/2013 71 VAL73 04/04/2013 99 VAL13 04/05/2013 11 VAL22 04/05/2013 11 VAL23 TABLE B (01 April-30 April)
B_DATE 04/01/2013 04/02/2013 04/03/2013 04/04/2013 (condition 1: month: April)
AND
condition 2: CALA1-> 11
AND
condition 3: COLA2-> VAL22)
I need to display all records for the months April to TABLE A,.
If the documents are not present in TABLE A for every 30 days, I need to display null, by reading DATE information in TABLE B
Expected results (sample)
Date COLA1 COLA2 04/01/2013 11 VAL22 04/02/2013 11 VAL22 04/03/2013 04/04/2013 04/05/2013 11 VAL22 Currently I have the following query
Select A_DATE, COLA1, COLA2 from TABLEA
where COLA1 = 11 and COLA2 in ('VAL22') and A_DATE between ' 2013-04-01 00:00:00.0' AND ' 00:00:00.0' 2013-04-30
Union of all the
Select B_DATE, null, null from TABLEB if date between ' 2013 - 04 - 01 00:00:00.0' AND ' 00:00:00.0' 2013-04-30
But I'm the duplicate records for the values in TABLE a.
Output current (sample)
Date COLA1 COLA2 04/01/2013 11 VAL22 04/01/2013 04/02/2013 11 VAL22 04/02/2013 04/03/2013 04/04/2013 04/05/2013 11 VAL22 04/05/2013 I tried with UNION and UNION ALL, but getting the same result.
Hello
Try this:
Select b.B_DATE, a, COLA1, one, COLA2
from TABLEB b
the left join TABLEA a
On a.A_DATE = b.B_DATE
and COLA1 = 11
and COLA2 in ('VAL22')
where B_DATE between to_date('2013-04-01','yyyy-mm-dd') AND to_date('2013-04-30','yyyy-mm-dd')
----
Ramin Hashimzade
-
Ask reg deleting logical lines dup
Hi gurus,
Could you please help with a query with the req as below
I have a table "tbl".
Col1 Col2
------ -------
A wind generator
A quiet
B Cn
B only
B Em
C only
D Wt
D what
D Em
the result of the query must be
Col1 col2
----- -------
A WtQu
B Cn
B only
B Em
C only
D WtQU
D Em
That is to say whenever I'm Wt and what (in col2) values for the same value of Col1 (here A and D), then the values must be concatinated and only one record with this concatinated value should appear.
Could you please help. Thanks in advance!
BR
SridhaTry:
with TEMP as (select 'A' COL1, 'Wt' COL2 from DUAL union select 'A' COL1, 'Qu' COL2 from DUAL union select 'B' COL1, 'Cn' COL2 from DUAL union select 'B' COL1, 'EM' COL2 from DUAL union select 'D' COL1, 'Wt' COL2 from DUAL union select 'D' COL1, 'Qu' COL2 from DUAL union select 'D' COL1, 'Em' COL2 from DUAL order by COL1,COL2) select TEMP.COL1, case when TEMP.COL2='Qu' then ((select T1.COL2 from TEMP T1 where T1.COL1=TEMP.COL1 and T1.COL2 = 'Wt')||TEMP.COL2) else temp.COL2 end from TEMP where col2!='Wt';
-
SQL Query logic-based price calculation
Hi Experts,
Here are my records in the table,
For each consignment:SHIPMENT_ID SHIP_PRICE SHIP_ADDT_PRICE PRODUCT_ID PRODUCT_QTY 1000 3.95 1 12 2 1000 0 0 17 1 1000 6.95 2 11 4 1001 0 0 17 1 1001 12.95 1 12 2 1001 12.95 2 11 4 1002 0 0 17 1 1002 20.95 1 12 2 1002 20.95 2 11 4
I need to get maximum shipprice (no need to examine the product and quantity).
then to manipulate as follows existing such as specimen
Max Shipprice line for each shipmentSHIPMENT_ID SHIP_PRICE 1000 (1*6.95)+(4-1*2) -- Maximum Price Calculation for particular shipment 1000 (1*0) -- Other product calculation for same shipment 1000 (4*2) -- Other product calculation for same shipment 1001 (1*12.95)+(4-1*2) -- Maximum Price Calculation for particular shipment 1001 (1*0) -- Other product calculation for same shipment 1001 (4*2) -- Other product calculation for same shipment 1002 (1*20.95)+(4-1*2) -- Maximum Price Calculation for particular shipment 1002 (1*0) -- Other product calculation for same shipment 1002 (4*2) -- Other product calculation for same shipment
(SHIP_PRICE) + (remaining PRODUCT_QTY if PRODUCT_QTY > 1 + SHIP_ADDT_PRICE)
Other than Max shipprice for each shipment
(PRODUCT_QTY + SHIP_ADDT_PRICE)
I am struggling here with logic how to proceed, any suggestions in connection with that?
Thank youwith ship as ( select 1000 SHIPMENT_ID,3.95 SHIP_PRICE,1 SHIP_ADDT_PRICE,12 PRODUCT_ID,2 PRODUCT_QTY from dual union all select 1000, 0, 0, 17, 1 from dual union all select 1000, 6.95, 2, 11 , 4 from dual union all select 1001, 0, 0, 17, 1 from dual union all select 1001, 12.95 , 1 , 12, 2 from dual union all select 1001, 12.95, 2 , 11, 4 from dual union all select 1002, 0 , 0 , 17, 1 from dual union all select 1002, 20.95 , 1, 12 , 2 from dual union all select 1002, 20.95, 2, 11, 4 from dual ) select shipment_id , case when (max_ship = ship_price and max_qty = product_qty) then (1* max_ship)+ ((max_qty - min_qty )* max_ship_aat_price) else (s.PRODUCT_QTY * s.SHIP_ADDT_PRICE) end max_price from (select max(ship_price) over (partition by shipment_id order by shipment_id desc) max_ship, max(product_qty) over (partition by shipment_id order by shipment_id desc) max_qty, min(product_qty) over (partition by shipment_id order by shipment_id desc) min_qty, max(ship_addt_price) over (partition by shipment_id order by shipment_id desc) max_ship_aat_price, s.shipment_id,s.SHIP_PRICE,s.SHIP_ADDT_PRICE,s.PRODUCT_ID,s.PRODUCT_QTY from ship s)s order by 1,2 desc
What do you expect?
-
Hi friends.
Please help on query below.
I want only the number of the channel, how can I do this example as below.
Select (upper ('cms0082')) twice;
of these, I want to single digit numb only 82 nor chanrecter nor the only digits 0 value.
Aude-If you have Oracle 10 g of output (at least), you can use a regular expression:
select to_number( regexp_replace((upper('cms0082')),'[^[:digit:]]','') -- removes all non-numeric characters ) from dual;
-
Reg: Query Get IP address and host name
Hi all!!!
Please help me, I need query for host name and the ip address... Please. its urgent
Concerning
MalekHello
In fact, my need is a record of front end during a deletion of the user. I want delete a record and what record
Without activated imperatives, it is not possible to track data.
Note: 60828.1 - Overview of Oracle Applications AuditTrails
https://MetaLink.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=60828.1Note: 105624.1 - Troubleshooting (Audit Trail)
https://metalink2.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=105624.1E Business suit health/Audit?
E Business suit health/Audit?Kind regards
Hussein -
Hi all!
Please help me with this query:
View the details of the employees whose salary exceeds the average salary of their own LOCATION
Thank you
Anthony.If you change your query using deptno instead of loc, the results remain the same:
SQL> select avg(e.sal) 2 , d.deptno 3 from emp e 4 , dept d 5 where d.deptno = e.deptno 6 group by d.deptno 7 / AVG(E.SAL) DEPTNO ---------- ---------- 1566,66667 30 2175 20 2916,66667 10 3 rijen zijn geselecteerd.
Note that the join to table dept can be ignored because emp also contains a column deptno.
Now if you want to select the average salary to each employee, you can use the table emp, like this:
SQL> select e.ename 2 , e.sal 3 , avg_sal.avg_sal 4 from ( select avg(e.sal) avg_sal 5 , d.deptno 6 from emp e 7 , dept d 8 where d.deptno = e.deptno 9 group by d.deptno 10 ) avg_sal 11 , emp e 12 where e.deptno = avg_sal.deptno 13 / ENAME SAL AVG_SAL ---------- ---------- ---------- SMITH 800 2175 ALLEN 1600 1566,66667 WARD 1250 1566,66667 JONES 2975 2175 MARTIN 1250 1566,66667 BLAKE 2850 1566,66667 CLARK 2450 2916,66667 SCOTT 3000 2175 KING 5000 2916,66667 TURNER 1500 1566,66667 ADAMS 1100 2175 JAMES 950 1566,66667 FORD 3000 2175 MILLER 1300 2916,66667 14 rijen zijn geselecteerd.
And now, it becomes easy to select employees with an average more wise pay high Department.
Note that, apart from the mentioned optimization earlier, you can also pass the second access of table emp using analytical functions.And if you don't want to see the average salary, you can use a subquery correlation like this:
SQL> select e.ename 2 , e.sal 3 from emp e 4 where e.sal > 5 ( select avg(e2.sal) 6 from emp e2 7 where e2.deptno = e.deptno 8 ) 9 / ENAME SAL ---------- ---------- ALLEN 1600 JONES 2975 BLAKE 2850 SCOTT 3000 KING 5000 FORD 3000 6 rijen zijn geselecteerd.
I hope this helps.
Kind regards
Rob. -
Reg: Query writing - please help
Hello
can you please help me get the results below?
select * from emp_time EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 03-12-08 03-12-08 y 03-12-08 220541 04-12-08 04-12-08 y 04-12-08 220541 18-02-09 18-02-09 y 18-02-09 220541 20-02-09 20-02-09 y 20-02-09 220541 24-02-09 24-02-09 y 24-02-09 220541 25-02-09 25-02-09 y 25-02-09 220541 26-02-09 26-02-09 y 26-02-09 220541 27-02-09 27-02-09 y 27-02-09 220541 28-02-09 28-02-09 y 28-02-09 220541 28-03-09 28-03-09 y 28-03-09 select * from emp_time where effective_date between to_date('02-20-09','mm-dd-yy') and to_date('02-24-09','mm-dd-yy'); EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 20-02-09 20-02-09 y 20-02-09 220541 24-02-09 24-02-09 y 24-02-09 Expected output: EMP_ID SHIFT_START_TIME SHIFT_END_TIME YARD_DEPARTURE EFFECTIVE_DATE 220541 20-02-09 20-02-09 y 20-02-09 220541 20-02-09 20-02-09 y 21-02-09 220541 20-02-09 20-02-09 y 22-02-09 220541 20-02-09 20-02-09 y 23-02-09 220541 24-02-09 24-02-09 y 24-02-09
Oracle Version: 11.2.0
Kind regards
Jame
Let me make a try also, because your statement only a min and max on XX, efective_date whatever the emp_id ;-)
I pretend not, this one is better (too many results that must be filtered with a separate), but it should be emp id independent
with emp_exist as (select emp_id
shift_start_time
shift_end_time
yard_departure
effective_date
of emp_time)
emp_fake as (select emp_id separate
to_date('02-20-09','mm-dd-yy') shift_start_time
to_date('02-20-09','mm-dd-yy') shift_end_time
, 'y' yard_departure
, to_date (20 February 09 ',' dd-mm-aa "") + effective_date level 1
of emp_exist
connect by level<=>=>
Select emp_id nvl (t1.emp_id, t2.emp_id)
nvl (t1.shift_start_time, t2.shift_start_time) shift_start_time
nvl (t1.shift_end_time, t2.shift_end_time) shift_end_time
nvl (t1.yard_departure, t2.yard_departure) yard_departure
nvl (t1.effective_date, t2.effective_date) effective_date
of emp_exist t1
join right emp_fake t2
on (t1.emp_id = t2.emp_id
and t1.effective_date = t2.effective_date)
order effective_date;
-
TABLE A
========
Q_ID
1
2
3
4
5
6
TABLE B
=======
Q_ID Q_NAME
1 INS
2 LED
UPD 3
INS 4
5 LED
UPD 66
44 INS
55 LED
UPD 66
Result
======
Need to update the Table A Qid WITH Max Q_ID in table B.
Basically to maximize A QID of table based on the Table B Q_ID
TABLE A
========
Q_ID
44
55
66
44
55
66
update from table_a a
set q_id =)
with t as)
Select b.q_id,
Max (b.Q_ID) on max_q_id (b.q_name score)
of table_b b
When status = 'A '.
)
Select t.max_q_id
t
where t.q_id = a.q_id
)
where q_id in)
Select b.q_id
of table_b b
When status = 'A '.
)
/
SY.
-
Need help with the query logic
I have 2 tables.
Table Tb1:
THE PLAN_ID PARENT_PLAN_ID ARGUMENT
Value null P1
P1 P2
P3 P2
P4 P1
Table tb2:
THE PLAN_ID ACTIVITY_ID PICKING ARGUMENT
P2 A1 5000
P2 A2 5000
P2 A3 5000
P3 A1 10000
P3 A2 10000
P4 A1 4000
I need to find the sum of the value of reduction of the workforce for each PLAN_ID which is parent root. In the case above, this is the argument PLAN_ID P1 (WHERE PARENT_PLAN_ID IS NULL). Please note that the value of the downsizing is repeated in the tb2 table. For example, the PLAN_ID P2 argument, the value of the downsizing is 5000 and not 5000 + 5000 + 5000.
The result of the output for the above data must be
THE ARGUMENT PLAN_ID DRAWDOWN
P1 19000
Published by: user10566312 on October 30, 2012 12:30with t as ( select t1.plan_id,t1.parent_plan_id,max(t2.DRAWDOWN) DRAWDOWN from tb1 t1,tb2 t2 where t1.plan_id = t2.plan_id(+) group by t1.plan_id,t1.parent_plan_id ) select plan_id,sum(drawdown) drawdown from( select connect_by_root plan_id as plan_id, nvl(DRAWDOWN,0) DRAWDOWN from t start with parent_plan_id is null connect by parent_plan_id = prior plan_id ) group by plan_id ; PLAN_ID DRAWDOWN ------- -------- P1 19000
Published by: JAC on October 30, 2012 13:23
Maybe you are looking for
-
Get more than 50% of the time on Shockwave.com "crossword" - also occurs on Addictinggames.com
-
New footprint software does not work with IE8 and FF3
I downloaded the latest version, but still, it does not solve problems with IE8 and FF3... Please, please... The main problem of the software cannot save the login information of website with Internet Explorer 8 + and Firefox 3 +. Thank youStewart Gr
-
No one knows how to delete a column, or changing the values in this column and leave the rest in a csv file? Example: CSV file has 70 rows and 40 columns. To remove a column or change its values. Thanks in advance.
-
any time that I'm going to make a change or something to download a popup comes up munnicipalite type me of said password, and I forget it so what do I do?
-
HP LaserJet P1006 and Mac running OS Yosemite
I can't get my desktop Mac to recognize my LaserJet P1006 since update today in Yosemite. Help!