Date of max from the entire lookup table
Hello people:
I hope that this discussion finds you well. I have 2 tables (MED_IMMUNO and LU_MED_IMMUNO). "MED_IIMMUNO" is the base table, and "LU_MED_IMMUNO" is the lookup table for the column 'IMM_REC '. Please see CFDS below:
TABLE: MED_IMMUNO
CREATE TABLE 'MED_IMMUNO' ('ID', 'EMP_ID' NUMBER, NUMBER OF "IMM_REC", "IMM_DATE" DATE, VARCHAR2 (255) 'IMM_NOTES', 'IMM_APPLICABLE' NUMBER, NUMBER OF "IMM_REFUSED")
/
INSERTION of REM in MED_IMMUNO
TOGETHER TO DEFINE
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (55,8474,5,to_date('12-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (56,8474,6,to_date('26-JUN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (57,8474,8,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (58,8474,9,to_date('13-FEB-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (59,8474,10,to_date('26-JUN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (60,8474,22,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (61,8474,4,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (62,8474,16,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (63,8474,17,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (64,8474,11,to_date('10-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (65,5900,1,to_date('19-JUN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (66,5900,2,to_date('17-JUL-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (67,5900,3,to_date('20-DEC-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (68,5900,22,to_date('19-JAN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (69,5900,4,to_date('19-JAN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (70,5900,14,to_date('19-JAN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (71,5900,17,to_date('19-JAN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (72,5900,16,to_date('19-JAN-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (73,10069,5,to_date('16-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (74,10069,6,to_date('24-FEB-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (75,10069,8,to_date('16-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (76,10069,9,to_date('24-FEB-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (77,10069,22,to_date('05-DEC-11','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (78,10069,4,to_date('02-JAN-12','DD-MON-RR'),null,null,null);
Insert into MED_IMMUNO (ID, EMP_ID, IMM_REC, IMM_DATE, IMM_NOTES, IMM_APPLICABLE, IMM_REFUSED) values (79,10069,16, null, null, null, null);
Try this:
WITH max_date AS
(
SELECT emp_id, imm_rec, max (imm_date) imm_date
OF MED_IMMUNO M
GROUP BY emp_id, imm_rec
)
DIS_MED_IMMUNO AS
(
SELECT DISTINCT M.emp_id
OF MED_IMMUNO M
)
tmp AS
(
SELECT *.
OF DIS_MED_IMMUNO
CROSS JOIN LU_MED_IMMUNO
)
Tmp.emp_id SELECT emp_id, tmp.ID, tmp. IMM_DESC, M.imm_date
OF tmp LEFT OUTER JOIN max_date M
ON tmp.emp_id = M.emp_id
AND tmp.ID = M.IMM_REC
ORDER BY tmp.emp_id, tmp.ord
Tags: Database
Similar Questions
-
I have a big event with the movement of the mouse on the many frameworks. My client may decide not to see the movement of the mouse. Is there a way I can remove the mouse from the entire project all at once, or what I should do a frame at a time?
-Stuart
Hello
Click any slide in the Panel of the film. Press Ctrl + A to select all slides. Right click on one of the blades and the point with the mouse context menu, and then clear the check box next to "show the mouse."
See you soon... Rick
-
How to create multiple hierarchies from the same physical table
Hi all
I have a physical table to join with a fact table: there are 3 different hierarchies, which share the last 2 levels inside the dimension table. It's the logic diagram of hierarchies:
Dimension services
-Business
-Sector
-Type
-Operator
-Product
Partner of dimension
-Partner
-Operator
-Product
Contractor of dimension
-Contractor
-Operator
-Product
All columns are in the same table physical source. I tried to create 3 table logic source from the same physical table, everyone with all the columns and create a hierarchy for each dimension table, but it gives me nQSError: 15011.
Any suggestion? Maybe the physical table alias can help for the creation of tables of different sizes?
Thanks in advance,
ConcerningHello
It is a basic rule that you cannot create multiple hierarchies in a single dimension table, so what you do is create three tables of alias and slip into MDB layer in 3 different sizes and on top these tables create 3 different dimension hierarchies.
Check if useful/correct
Thank you.
-
XML from the master-child tables
Hello
Just post here again for a quick response.
XML from the master-child tables
Best regards
HariHello
Using SQL/XML functions is the way to go in this case.
SQL> select xmlroot( 2 xmlelement("ROWSET", 3 xmlagg( 4 xmlelement("MASTER", 5 xmlforest(tm.master_id, tm.master_name, tm.master_location), 6 ( 7 select xmlagg( 8 xmlelement("CHILD", 9 xmlforest(tc.child_id, tc.child_name, tc.child_location) 10 ) order by tc.child_id 11 ) 12 from t_child tc 13 where tc.master_id = tm.master_id 14 ) 15 ) order by tm.master_id 16 ) 17 ) 18 , version '1.0') 19 from t_master tm 20 where tm.master_id = 1 21 ; XMLROOT(XMLELEMENT("ROWSET",XM --------------------------------------------------------------------------------
1 master name master location 1 child name 1 child location 1 2 child name 2 child location 2 3 child name 3 child location 3 Note that the first XMLAgg is optional here, since you want just a MASTER at a time.
But if you need an XML document containing several masters, he will work as well.Alternatively, you can write a similar query with a GROUP BY clause (no correlated subquery, but a join between the master and the child instead):
select xmlroot( xmlelement("ROWSET", xmlagg( xmlelement("MASTER", xmlforest(tm.master_id, tm.master_name, tm.master_location), xmlagg( xmlelement("CHILD", xmlforest(tc.child_id, tc.child_name, tc.child_location) ) order by tc.child_id ) ) order by tm.master_id ) ) , version '1.0' ) from t_master tm join t_child tc on tc.master_id = tm.master_id where tm.master_id = 1 group by tm.master_id, tm.master_name, tm.master_location ;
Published by: odie_63 on June 15, 2011 15:06
-
Hello
I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships
Details of the table
Alert-1 - AlertCode (FK), AlerID (PK)
2 AlertCode-AlertDefinition-(PK)
Help, please
----------
Hi Vincent,.
I think that you have not worked on adf 12.1.3. In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link
---
-
How to remove duplicates from the PL - SQL table?
Hi gurus,
I have a PL - SQL table with the following structure
Authors (SR_NO, Auth_Code, Change_Date, cost)
This table is filled using a slider. However, this table can have a few lines in double (for column (Auth_Code)
for example
I need to get the above result set select the separate lines of Auth_Code including the Change_Date is maximum (and store in another PL - SQL table for treatment later or even the removal of this table will be also!)SR_NO Auth_Code Change_Date Cost 1 A1 14-FEB-09 08.18.47 AM 11.00 2 A2 14-FEB-09 08.18.56 AM 2839.00 3 A1 15-FEB-09 08.00.02 AM 1299.00 4 A1 15-FEB-09 07.00.00 AM 789.00 5 A3 14-FEB-09 08.18.56 AM 312.00 6 A4 14-FEB-09 08.19.02 AM 233.00
of the data A1 is duplicated and a maximum Change_Date above = 15 February 09 08.00.02 AM.
Where my PL - SQL Table that results must have given below
I'm not very aware of the PL - SQL tables and there is no chance to change the existing cursor that fills the data in this table PL - SQL.SR_NO Auth_Code Change_Date Cost 2 A2 14-FEB-09 08.18.56 AM 2839.00 3 A1 15-FEB-09 08.00.02 AM 1299.00 5 A3 14-FEB-09 08.18.56 AM 312.00 6 A4 14-FEB-09 08.19.02 AM 233.00
I guess that I need to compare each record of PL - SQL table with others, but do not know how to do this.
Could you please help?Hello
Like this?:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0 Connected as hr SQL> SQL> with data as( 2 select 1 as SR_NO, 'A1' as Auth_Code, to_date('14-FEB-09 08.18.47', 'dd-mon-yy hh24:mi:ss') as change_date, 11.00 as cost from dual union all 3 select 2 as SR_NO, 'A2' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date, 2839.00 as cost from dual union all 4 select 3 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 08.00.02', 'dd-mon-yy hh24:mi:ss') as change_date, 1299.00 as cost from dual union all 5 select 4 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 07.00.00', 'dd-mon-yy hh24:mi:ss') as change_date, 789.00 as cost from dual union all 6 select 5 as SR_NO, 'A3' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date, 312.00 as cost from dual union all 7 select 6 as SR_NO, 'A4' as Auth_Code, to_date('14-FEB-09 08.19.02', 'dd-mon-yy hh24:mi:ss') as change_date, 233.00 as cost from dual) 8 select * from data d where change_date = (select max(change_date) from data d2 where d.auth_code = d2.auth_code); SR_NO AUTH_CODE CHANGE_DATE COST ---------- --------- ----------- ---------- 2 A2 14/02/2009 2839 3 A1 15/02/2009 1299 5 A3 14/02/2009 312 6 A4 14/02/2009 233 SQL>
Kind regards
-
How to get the old data 6 months from the current date?
Hi friends,
I have a table which includes historical data, which are having more than 1 years old data. The historical table gets updated once a week. My requirement is that I should get the latest data from the week of each month for 6 months according to the current data. I use oracle 10g.
Can you please someone help in this.
Thanks in advanceSELECT last_day (ADD_MONTHS (TRUNC (SYSDATE, 'mm'),-LEVEL))-7 start_dt.
LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE, 'mm'),-LEVEL)) end_dt
OF THE DOUBLE
CONNECT BY LEVEL<=>=>change as a result, I have provided you the start and end dates for your logic...
-
Date of Max in the default selection of the command prompt
Hello
in the command prompt, I have dates, I need a maximum date in default selction of the guest of
How to give max ("table". "Colum") "You write the query as
SELECT MAX (Time.Date) saw_0 "SA".
at the prompt to-> see the-> results of SQL, use this queryIf help pls mark as correct/good
Published by: on November 22, 2012 vieren 06:33
-
getting data to and from the DOS window
I use IPERF to measure flow and data errors.
This is done by entering data in a window DOS command via the keyboard, then physically reading the data from the BACK window.
I wish I had a LabView program to be able to write in this window and read back the response.
Y at - it a terminal emulator to send the data? Is it possible to get the text sent in LabView that normally goes to the BACK window?
Any ideas would be appreciated: even willing to pay for a solution.
-Steve Girard
Broadcom Corp.
Don't know not how IPERF works but you should be able to use the Exec.vi system to send the command and then pull the output on the output terminals or standard deviation.
-
Date and days for the entire year come in the column
Hi all
I have 2 column 1 is the Date and day 2
And I have a button, I need when I press enter then his show all the year date in the date and day column in the column of day for example
Date - day+.
* 1 - jan - 2009 - Thursday *.
* 2 - jan - 2009 - Friday *.
* 3 - jan - 2009 - Saturday *.
And like on
I hope that you guys understand
Concerning
Wasim IsmailHai,
This means, you must fill in the block record multi that has 2 columns (1 is the date, and the other is updated.).
For this try this in the trigger WHEN BUTTON PRESSED the button.
DECLARE Dt_Date DATE; BEGIN GO_BLOCK ('
'); CLEAR_BLOCK(NO_VALIDATE); FIRST_RECORD; Dt_Date := TO_DATE('01-JAN-2009'); LOOP : .TI_DATE := TO_CHAR(Dt_Date, 'DD-MON-YYYY'); : .TI_DAY := TO_CHAR(Dt_Date, 'DAY'); EXIT WHEN TO_CHAR(Dt_Date, 'YYYY') <> TO_CHAR(Dt_Date + 1, 'YYYY'); -- If next year reaches, exit from the loop. Dt_Date := Dt_Date + 1; NEXT_RECORD; END LOOP; END; Kind regards
Manu.
If this answer is useful or appropriate, please mark. Thank you.
-
Restore data deleted by mistake from the production oracle table
Forms [32 bit] Version 10.1.2.0.2 (Production)
Oracle Toolkit Version 10.1.2.0.2 (Production)
PL/SQL Version 10.1.0.4.2 (Production)
Oracle V10.1.2.0.2 - Production procedure generator
PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
Query Oracle 10.1.2.0.2 - Production Designer
Oracle virtual graphics system Version 10.1.2.0.2 (Production)
The GUI tools Oracle Utilities Version 10.1.2.0.2 (Production)
Oracle Multimedia Version 10.1.2.0.2 (Production)
Oracle tools integration Version 10.1.2.0.2 (Production)
Common tools Oracle area Version 10.1.2.0.2
Oracle 10.1.0.4.0 Production CORE
This morning I deleted data tables of production not having is not all correct conditions. This removed some required data.
Y at - it a command to retrieve these data? Help is appreciated. The table name is
dept_staff
"where SCHEDULE_DATE between ' 9-mar-2014' and 15-mar-2014."
I used this query
SELECT * from dept_staff
FROM TIMESTAMP
TO_TIMESTAMP ('2014-03-03 07:00 ',' YYYY-MM-DD HH)
"WHERE the SCHEDULE_DATE between ' 9-mar-2014' and 15-mar-2014."
Is this OK. Is - this show what existed in the table at 07:00 today? before deleting?
-
Display data as absent from the pivot table tab
Hi all
I added a column for measures in the PivotTable. But I don't have all the data in this column c in my report itself. When I clicked the VIEW DATA AS particular column option is missing... what was not right here? Please let me know.
This type of emergency. TIAIf you are filling 'yes' or ' "then it will not appear"Show the data as"option because this option is only for numeric data type columns. You can not show age % for a varchar column. Pull this column lines or columns, accordingly and it goes to show that data. In the section all the columns must be in double or integer data type is a numeric data type and that they should have some rule aggregation applied to this topic.
You must include the varchar columns in section rows or columns.
Kind regards
Sandeep -
Get information from the Bank of Tables HZ
Hi I mostly use CE_BANKS_V for the information of the Bank, but in case I want this HZ_PARTIES table information so how I can get because there is presented data of parties, people, etc.. i don't know which one I should mention to get only the condition information stores.
Kind regards
Shakeel KhanHi Shakeel
If you see the script for ce_banks_v, it uses the table hz_parties only. You can use the following query (this one is taken by the script of ce_banks_v only):
Select * from
hz_parties bankparty, hz_code_assignments bankca
where
bankparty.party_type = "ORGANIZATION".
AND bankca.class_category = 'BANK_INSTITUTION_TYPE. '
AND bankca.class_code IN ('BANK', 'CENTRE')
AND bankca.owner_table_name = 'HZ_PARTIES. '
AND bankca.owner_table_id = bankparty.party_id
AND NVL (bankca.status, 'A') = "A".Thank you
Serge -
Update the data to uppercase in the parent/child tables
Hi gurus!
In production, we have a table product and that is in reference by many tables making parent child relationship. By mistake, we realized last month some products have been added to lowercase and now we have a request to update all these product codes uppercase so that existing code that use these tables have no impact. Appreciate if you can give an idea about how can I update the existing data in the table parent uppercase as well as child records?
Concerning
SriAre the product code that you need to update what is stored in the tables of children? If Yes, then you must do it in several steps, something like:
Identify the child tables
SELECT table_name, constraint_name FROM user_constraints WHERE r_constraint_name = (SELECT constraint_name FROM user_constraints WHERE table_name = 'PRODUCT_TABLE' and constraint_type = 'P');
Create new product of upper-case code in the product table:
INSERT INTO product_table SELECT UPPER(product_code), other_columns FROM product_table WHERE product_code <> UPPER(product_code);
Update the children tables for caps product codes
UPDATE child1 SET product_code = UPPER(product_code) WHERE product_code <> UPPER(product_code);
Finally, remove the tiny product_table product codes
DELETE FROM product_table WHERE product_code <> UPPER(product_code);
John
-
Select DataSet from the pl/sql table
Hi Experts,
I need to create a metric of OEM 12 c extensions. I must create a pl/sql code that can return results to OEM.
The following code works in OEM. But the problem is that I need to create a permanent table for this case.
Could you please tell any other option available to do this without creating additional objects at the database level?
Based on the requirement of the OEM, the end of the script, I have to do something like ' open: 1 to select in the <>' to return the results in a table.
Thank you.
###########################################################################################
DECLARE
TYPE cur_type IS REF CURSOR;
CURSOR c1 IS
SELECT distinct (owner: '.) ' || queue_table) as queue_table FROM dba_queues;
l_cur_string VARCHAR2 (200);
C2 cur_type;
v_queue VARCHAR2 (128);
number of v_ready;
BEGIN
run immediately "remove sys.testing";
FOR v_queue_table IN c1 LOOP
l_cur_string: ='select q_name, count (*) from ' | v_queue_table.queue_table | ' where State = 0 or (State = 1 and sysdate > nvl (delay, enq_time)) q_name group ';
OPEN c2 FOR l_cur_string;
LOOP
C2-FETCH INTO v_queue, v_ready;
OUTPUT WHEN c2% NOTFOUND;
run immediately ' insert into sys.testing values (: v_queue,: v_ready) "using v_queue, v_ready;"
OPEN: 1 for select * from sys.testing;
commit;
END LOOP;
CLOSE C2;
END LOOP;
END;
###################################################################################
In addition, committing inside of cursor loops are false. You should never engage at the end of a business logic operation, NEVER in cursor loops.
Something along these lines (untested) is probably what you want:
var refcursor rc;
declare
SQL varchar2 (32767).
Start
SQL: = q'[select
table_name,
TO_NUMBER)
ExtractValue)
XmlType)
dbms_xmlgen. GetXml ("select count (*) c to ' |") table_name | ((' where State = 0 or (State = 1 and sysdate > nvl (delay, enq_time)) q_name group '))
(("/ LINES/LINES/C ')) County
from (select distinct owner |'.) ' || queue_table as table_name dba_queues)]';
Open: rc for sql.
end;
/
print rc;
Maybe you are looking for
-
Can anyone help. I am trying to access wifi in my hotel on my iphone 6 s. getting hotel access page ok and nourishing in username and password but will then loop back to the original access page aking username and password again. Everyone elses phone
-
After installing Windows 10 PC is on an infinite reboot cycle, I tried the system diagnostics and it meets the test. I also tried to change the BIOS set up but nothing seems to work and it keeps restarting now. After restarting 3 times, it shows that
-
sound on HP ENVY 15-j035eo Notebook PC problems
Hello I have a HP ENVY 15 - j035eo Notebook PC and suddenly all his disapered. I've updated to windows 8 to 8.1 worked sound for a 1-2 weeks . When I click on the speakers says (translated from Swedish ;-)) "Sound upgrades for the following problems:
-
I tried to remote desktop access and you can find the program.
-
User (select) switch without having to type the password
Hello I would like to be able to switch between 2 user accounts without having to type the password, but I don't want another user (or an unknown person, to get to the original session logon screen) to be able to connect to these accounts without pas