Clarification of SQL query
Script to use:
create table time_dim as select rownum id, trunc (sysdate) + level double dates to connect by level < 100;
ALTER table time_dim add constraint time_dim_pk primary key;
create table cust_emp (cust_name varchar2 (10), integer date_of_join_seq, around date_of_marriage_seq);
ALTER table cust_emp add constraint time_dim_join_fk Foreign key (date_of_join_seq) makes reference to time_dim (id);
ALTER table cust_emp add constraint time_dim_marriage_fk Foreign key (date_of_marriage_seq) makes reference to time_dim (id);
insert into cust_emp values ('cust1', 22, 33);
insert into cust_emp values ('cust2', 2, 40);
Question:
Here date_of_join_seq and date_of_marriage_seq are in fact ID pointing to the date indicated in the table time_dim
and I want back the dates of this table.
CUST_NAME DATE_OF_JOIN_SEQ DATE_OF_MARRIAGE_SEQ JOIN_DATE MARRIAGE_
---------- ---------------- -------------------- --------- ---------
22 33 Date2 Date1 cust1
2 40 Date3 Date4 cust2
where date1,date2,date3date4 are based on the time_dim table values
SQL> select cust_name 2 , date_of_join_seq 3 , date_of_marriage_seq 4 , t.dates date_of_join 5 , t1.dates date_of_marriage 6 from cust_emp c 7 join time_dim t 8 on c.date_of_join_seq = t.id 9 join time_dim t1 10 on c.date_of_marriage_seq = t1.id; CUST_NAME DATE_OF_JOIN_SEQ DATE_OF_MARRIAGE_SEQ DATE_OF_J DATE_OF_M ---------- ---------------- -------------------- --------- --------- cust1 22 33 29-JUL-15 09-AUG-15 cust2 2 40 09-JUL-15 16-AUG-15 SQL> select cust_name 2 , date_of_join_seq 3 , date_of_marriage_seq 4 , max(decode(date_of_join_seq, id, dates)) date_of_join 5 , max(decode(date_of_marriage_seq, id, dates)) date_of_marriage 6 from cust_emp c 7 join time_dim t 8 on c.date_of_join_seq = t.id 9 or c.date_of_marriage_seq = t.id 10 group 11 by cust_name 12 , date_of_join_seq 13 , date_of_marriage_seq; CUST_NAME DATE_OF_JOIN_SEQ DATE_OF_MARRIAGE_SEQ DATE_OF_J DATE_OF_M ---------- ---------------- -------------------- --------- --------- cust1 22 33 29-JUL-15 09-AUG-15 cust2 2 40 09-JUL-15 16-AUG-15
Tags: Database
Similar Questions
-
Clarification of the SQL query in 2 day + Guide APEX
I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).
The code is:
SELECT d.DEPARTMENT_ID,
d.DEPARTMENT_NAME,
(select count (*) from oehr_employees where department_id = d.department_id)
"Number of employees", he said.
substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',
c.COUNTRY_NAME 'place '.
OEHR_DEPARTMENTS d,
E OEHR_EMPLOYEES
OEHR_LOCATIONS l,
C OEHR_COUNTRIES
WHERE d.LOCATION_ID = l.LOCATION_ID
AND l.COUNTRY_ID = c.COUNTRY_ID
AND e.department_id = d.DEPARTMENT_ID
AND d.manager_id = e.employee_id
AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)
I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.
What does this string? This code simply checking that d.department_name isn't NA?
I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.
Thank you.
2899145 wrote:
Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.
In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report
page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.
for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.
However, given that the document is a guide for the development of the APEX, I guess the command:
AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0
done something valuable, and I do not recognize what is exactly the value.
From a practical point of view why would I need to include this conditional statement? Which only added to the application?
Looking at the guide in question, it is clear that the
AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.
If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...
-
Hello
I need to write an efficient query because the query about 4 checks to be made on the lines before you return one row. Here's a sample script in query to create the table:
CREATE TABLE "myschema". "" Complaint. "
(
"Compalint_ID" NUMBER (20.0).
"ReplyTime' NUMBER,-it would be in a few minutes
"CREATION_TIME' TIMESTAMP (6).
NUMBER OF 'STATUS ',.
"TYPE" NUMBER
"CH_PKRTBL_Complaint_ID" ("Compalint_ID") PRIMARY KEY CONSTRAINT
USING INDEX PCTFREE, INITRANS 10 2 MAXTRANS 255 CALCULATES STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE 'myspace' ENABLE
) PCTFREE, PCTUSED, INITRANS 40 10 1 MAXTRANS 255 NOCOMPRESS SLAUGHTER
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "myspace";
CREATE UNIQUE INDEX "myschema". "" CH_PKRTBL_Complaint_ID "WE"myschema ". "" Complaint "("Compalint_ID")
PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE "myspace";
ALTER TABLE 'myschema. ' ' KEY PRIMARY complaint ' ADD CONSTRAINT 'CH_PKRTBL_TKTID' ('Compalint_ID')
USING INDEX PCTFREE, INITRANS 10 2 MAXTRANS 255 CALCULATES STATISTICS
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 DEFAULT USER_TABLES)
TABLESPACE 'myspace' ENABLE;
I want to write an efficient pl/sql-sql query with the least time to return a row based on four following priorities/controls in the order specified below:
1 return any line that contains a TYPE = 11
2. If no line found for 1 check then
calculate a difference in time for all of the lines as: time_difference (CREATION_TIME - ReplyTime)
and back to the line that has more big differene in - ve (it is the line which expired first)
3. If now the found line to check then the 2
rank next where STATUS = 22
4. If no line found to check then the 3
calculate a difference in time for all of the lines as: time_difference (CREATION_TIME - ReplyTime)
and back to the line that has a smaller difference in + ve (it is the line that will expire then)
Kindly help me in this task.
Thank you.@1
I have the suggestion of Daniel while avoiding reserved words and now I see an error in copy/paste complaint_ casetypestatus when 22 then 22 end check3@2
Bilal already you made in the right direction, anyway: as many others pointed out that you can not combine functions of the group the way which you intend to so using functions analytical has been the only issue keeping all lines and the calculation of the required amounts and charges in the query internal to combine in the outer query.
complaint_type case when 11 11 then end keeps only the 11 complaint_type all other complaint_type null values
Max (case complaint_type when 11 11 then complete) on check1_max (order by NULL rows between unbounded preceding and following unbounded), calculates the global maximum of the expression (in all the rows of the table)@3
I used systimestamp - (creation_time + reply_time / 60/24) just to produce a positive or negative number as your time_difference (CREATION_TIME - ReplyTime) somehow confused me (timestamp less number gives timestamp if positive or negative is not an appropriate question) so the above expression as used so far is something you know how (re) set. Other required clarification/explanation at this stage.@4
If the fraction of the second precision is not necessary using the date data type should be sufficient (environmental CAR you cannot rule out dealing with the events with the same timestamp) and what is the thrown error using systimestampConcerning
Etbin
-
Hello
I post this question for clarification. I have a report that is based on a SQL query area.
Place automatically APEX sql in the tables, all THE results of a query if it is in a region of report? Or y at - it a step that the developer must do to retrieve the columns of the sql query in a table.
I'm working with checkboxes, and I read up on top of the api APEX_APPLICATION. This part is still unclear.
Your comments would be appreciated!
KeishaHi Keisha,
You should have a read of: [http://download-uk.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CHDHFACG] that explains the use of checkboxes on the reports.
I guess the 'picture' you refer to are APEX_APPLICATION. G_F01 up APEX_APPLICATION. Paintings of G_F50? If so, they are built when you submit the page and are based on elements with attributes of 'name' of 'f01' up to 'f50' in the HTML tags. You don't need to do anything beforehand to create these, which is done automatically for you by the Apex. But, notes, however, that only the checked boxes are presented with a page - so if your username is checked, say, 3 of the 10 boxes, table will contain only 3 points not 10 (with each element of the table that contains the attribute 'value' of a checkbox).
Andy
-
Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit
I have this SQL query:
DECLARE TABLE (@DataTypeTable)
Name varchar (128).
TypeID INT)-Add comma delimeted type data in the temporary table names
INSERT INTO @DataTypeTable (name)
SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')SELECT the name OF @DataTypeTable
That takes a comma delimited by the string and returns the string as a table. It works correctly in Microsoft SQL Server Management Studio. When I run this as a stored procedure I return nothing. There are no errors, SQL or otherwise. I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above). Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?
Thanks in advance.
-
HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.
As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock
There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
Help me pls!with respect,
Ray
Hello
You have two cases:
(1) connect to the database with string (link a string of connection information), and then type something like this:
Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)(2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.
There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl
Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.
Kind regards
-
I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.
I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.
Thanks in advance for your help,
Jim
Jim,
Just to be sure, have you used 'is' instead of '=' in this command?
This makes all the difference in this command.
Cerati
-
Support of SQL query: what tasks are Sunday from 07:00 - 12:00
Hello tide Admins.
I need to do a SQL query that can give me a list of jobs that are running on a given (Sunday) day from 07:00 - 12:00. Our environment is not a maintenance window. Therefore, whenever there is application of patches or upgrades, it causes more work and risk of failure of the tide tasks. By moving jobs over the period from 07:00 - 12:00 Sunday, patch can be completed without disrupting the calendar.
Im not the best at the SQL script and can not get my script to work. any help would be great. Here's what I have so far. I get the error ' could not find identifier multi-player jobmst.jobmst_name. IM using Tidal 6.0.3 with SQL for DB Admeral table.
SELECT dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
FROM dbo.jobdtl INNER JOIN
dbo.jobmst ON dbo.jobdtl.jobdtl_id = dbo.jobmst.jobdtl_id
WHERE (dbo.jobdtl.jobdtl_fromdt > 14 September 2016 06:00 ') AND (dbo.jobdtl.jobdtl_fromdt< '09/11/2016="" 012:00:00="">
GROUP OF dbo.jobdtl.jobdtl_id, dbo.jobmst.jobmst_prntname, dbo.jobmst.jobmst_name
Hi Jeff
The time window from the jobdtl returns only jobs that have an early start time and windows of time from beginning to the end, so there may be some tasks which are not time bound but have dependencies on other jobs, variables, etc.
Here are the 2 SQL queries against the table jobrun and jobmst:
-The list of jobs that took place last Sunday between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_time FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_time > = 9/11/2016 07:00 ' and jobrun.jobrun_time<= '9/11/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_time-For a list of jobs that are scheduled to run on Sunday to come between 07:00 and 12:00
SELECT jobmst.jobmst_prntname, jobmst.jobmst_name, jobrun.jobrun_esttime FROM jobrun
JOIN jobmst on jobrun.jobmst_id = jobmst.jobmst_id
WHERE jobrun.jobrun_esttime > = 9/18/2016 07:00 ' and jobrun.jobrun_esttime<= '9/18/2016="" 12:00="">=>
ORDER BY jobrun.jobrun_esttimeARO
The Derrick
-
How to get the value of a column in sql query?
Hi, anyone knows how to get the value of a column in sql query?
Here is my code, the value must be 1350079224397 in my PB, but I get 0
QString query ("SELECT version FROM db_version");
QVariant result = sda.execute (query);
QVariantMap versionMap = result.toList () such () .toMap ();
If (! versionMap.IsEmpty ())
{
qDebug()<"Version: "="">"Version:><>
}OK, I have the solution
QString query ("SELECT version as version FROM db_version");
-
Hi team,
I'm looking for a SQL query check data (ECC + CallVariable) due to a RESULT of SCRIPT EXECUTE when you ask an external VRU with a translation route to VRU with a 'run external Script '.
In my view, that the data are analyzed between the termination call detail + termination call Variable.
If you have already such a SQL query I would be very grateful to have.
Thanks and greetings
Nick
Omar,
respectfully, shorten the interval of a day might not be an option for a history report ;-)
I recommend to take a look at the following SQL query:
DECLARE @dateFrom DATETIME, @dateTo DATETIME
SET @dateFrom = ' 2014-01-24 00:00:00 '
SET @dateTo = ' 2014-01-25 00:00:00 '
SELECT
TCV. DateTime,
TCD. RecoveryKey,
TCD. RouterCallKeyDay,
TCD. RouterCallKey,
VME. EnterpriseName AS [ECVEnterpriseName],
TCV. ArrayIndex,
TCV. ECCValue
OF Termination_Call_Variable tcv
JOIN THE
(SELECT RouterCallKeyDay, RouterCallKey, RecoveryKey IN Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime)< @dateto)="">
THE tcv. TCDRecoveryKey = tcd. RecoveryKey
LEFT OUTER JOIN Expanded_Call_Variable VME ON tcv. ExpandedCallVariableID = VME. ExpandedCallVariableID
WHERE the tcv. DateTime > @dateFrom AND tcv. DateTime<>
With variables, you can set up your code (for example, you could write SET @dateFrom =? and let the calling application to fill in the DateTime for you).
In addition, join two large tables with all the lines, as you did (TCD - TCV) is never a good option.
Another aspect to consider: all the ECC is actually arrays (always), is not good to leave aside the index value (tcv. ArrayIndex).
G.
-
DA on updatable report items Sql query using the class
Request Express 4.2.5.00.08
10-11 g Oracle
I have a page, so it has a link/button when he clicks then modal region will appear. Modal region has a as a table (Type SQL Query (updateable report)). All work very well so far.
However, I've now added some complex things.
for example. My region is based on the query of SQL Type (editable report).
SELECT id, name of family, Traghetti, area, d_date, start_time, End_time, displacement, role of table where id =: P10_ID;
I can also add a new line of course.
My problem is, (point) Shift display based on the value of Start_Time point) and so I made sure the class for two items.
for example, Start_Time (' class = "st_tm" ') and Maj ('class to = "Shift_time" '). Start_Time is based on (LOV) and shift is off the point in the sql query, but change the Start_Time.
And now, I created the DA.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
1. action: set value
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
The element affected: P10_X1 (it is a hidden item)
2. action: Plsql Code
Code: start to null; end;
Page items to submit: P10_X1
3. action: Plsql Code
Code: start
If: P10_X1 between '03' AND '11' then
: P10_X1: = 'EARLIES ';
elsif: P10_X1 then '12' and '18'
: P10_X1: = 'LATES ';
on the other
: P10_X1: = 'NIGHTS';
end if;
end;
Page items to submit: P10_X1
NOW another DA
Event: change
Article (s) P10_X1
Condition (in list)
value (HASTY, LATES, NIGHTS)
Action:
Set type: Expression Javascript
The JavaScript Expression: $(this.triggeringElement) .val ();
Affected item:
Selection type: jQuery Selector
jQuery Selector:. Shift_time
Well, I look forward all the above work well, but I'm having a problem.
If I have more than 1 lines on a modal region and if I change the Start_Time value for a row then MAJ (point) is changing but he effect on all lines.
I want, if I make the changes on the line line # 2 while only 2 # MAJ (point) must be not performed any other lines?
Help, please!
Kind regards
RI
I found the solution me thank you.
I removed all the DA mentioned above and created a new.
1. event: change
Selection type: jQuery Selector
jQuery Selector: .st_tm
Condition: No.
Scope of the event: dynamic and light on page load.
Action (Javascript code)
ROW_ID = $(this.triggeringElement).attr('id').substr (4);
If ($(this.triggeringElement). val() > = 03 &. val() $(this.triggeringElement))<= 11)="">=>
.Val ('EARLIES') $(«#f11_» + row_id);
}
ElseIf ($(this.triggeringElement). > 11 val() & $(this.triggeringElement). val())<= 18)="">=>
.Val ('LATES') $(«#f11_» + row_id);
}
ElseIf (. val() > $19 (this.triggeringElement)) {}
.Val ('NIGHTS') $(«#f11_» + row_id);
}
also created another DA because I have a disabled report items.
Event: before the page is sent.
$('_:_disabled').removeAttr ("disabled");
and finally created manual process of DML for tabular and everything works fine. (Insert, Update, and delete).
Kind regards.
-
SQL query to retrieve only numbers to a string variable
Dear all Experts,
I have a requirement in one of my projects where I need to extract only the numbers present in the variable.
for example:
BANK_ACCOUNT_NUMBER = 12345-67890';
BANK_ACCOUNT_NUMBER = 12345 67890';
BANK_ACCOUNT_NUMBER = "123.456.7890";
BANK_ACCOUNT_NUMBER = 123-A456BC7890D';
In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.
Please suggest me the query how to extract numeric values from varchar variable.
Thank you
Knockaert
select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
See you soon,.
Manik.
-
Calculation of the time wall of a SQL query.
Hello
While trying to discover the time of running a SQL query (wall time) I read in one place that CPU_TIME/EXECUTIONS of v$ SQLAREA, is the precise runtime we can come close to.
I can't use "set timing on ' or 'DBMS_UTILITY. GET_TIME' that I need to extract the execution time of the story because the query will be drawn to an end, and I need to know how long it took to DB level and compare it with the end time before calculating the % of time used in the DB level total.
Maybe another way to track sessions and the user TKPORPOF but now I donot want to take the help of the ADMINISTRATOR at this initial stage.
Is CPU_TIME/EXECUTIONS of v$ SQLAREA where (SQL_TEXT) AS "SELECT... OF... %'; should be enough?
user2925917, yes as Brian already answered your understanding as posted above seems correct. Except in the case where there has been only a running query you will download an average time. The problem with averages is that one or two unusual executions that can skew the average, but in most cases the average will be probably fairly accurate.
- -
HTH - Mark D Powell.
-
How to do a validation based on the SQL query?
Hello
I have a requirement to perform a validation on a field (messageTextinput) in my page OAF.
When I click the button apply, the value in this field is validated based on a SQL query (for example, the value in the field NOT IN (value1 select from table1).)
Help, please.
Best regards
Joe
1. create a SQL query based VO, XXVO. For example:-SQL query is select xx_table;
2. Enter the "Apply" button click event in the controller and run the AM method passing the value entered by the user in the given field, for example:-value is VAL1
3. in the method of the AM, get a handle of the VO, the whereClause and run.
OAViewObjectImpl vo = findViewObject ("XXVO1"); XXVO1 is the name of the instance of the VO above, XXVO
vo.executeEmptyRowSet ();
vo.setWhereClause (null);
vo.setWhereClause ("value =" + VAL1 + "'");
vo.executeQuery ();
If (VO. GetRowCount() > 0)
A record is with the value of VAL1. Perform the required action
I hope this helps.
-
Single SQL query for the analysis of the date of customs declaration under the table of Stock codes
Dear all,
Please tell us a single SQL query for the below,
We have a Table of Stock as shown below,
STOCK_TABLE
ITEM_CODE
(item code)
BAT_NO
(lot no.)
TXN_CODE
(transaction code)
DOC_NO
(number)
BOE_DT
(date of the customs declaration)
I1
B1
I1
I2
I3
B70
I4
B80
I5
B90
T102
1234
JULY 2, 2015
I6
B100
We have to find the date of customs declaration (i.e. the date when the items have come under this particular table) for items that are not attached to any document (that is, who have TXN_CODE, DOC_NO and BOE_DT fields with a NULL value).
For each item in the table of actions, which is not attached to any document, the customs declaration date is calculated as follows.
- If (code section, lot number) combination is present under HISTORY_TABLE, the date of customs declaration will receive the UPDT_DT, the transaction code (TXN_CODE) is an IN or transactions (which can be analyzed from the TRANSACTIONS table).
- If (code section, lot number) combination is NOT currently at the HISTORY_TABLE (or) the transaction code respective to item - batch number combination code is an operation then customs declaration date will be the date of the document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD that contains the element of that particular lot.
- If the case 1 and case 2 fails, our customs declaration date will be the last date of document (DOC_DT) that we receive from one of the 3 tables IN_TABLE_HEAD containing that particular item and the BAT_NO in expected results will be that corresponding to this document, as appropriate, to another NULL.
- If the case 1 or case 2 is successful, the value of the last field (in the output expected, shown further below) BATCH_YN will be 'Y', because it fits the lot. Otherwise it will be 'n'.
HISTORY_TABLE
ITEM_CODE | BAT_NO |
TXN_CODE
DOC_NO
UPDT_DT
I1
B1
T1
1234
JANUARY 3, 2015
I1
B20
T20
4567
MARCH 3, 2015
I1
B30
T30
7890
FEBRUARY 5, 2015
I2
B40
T20
1234
JANUARY 1, 2015
TRANSACTION
TXN_CODE | TXN_TYPE |
T1 | IN |
T20 |
OFF
T30
ALL THE
T50
IN
T80
IN
T90
IN
T60
ALL THE
T70
ALL THE
T40
ALL THE
IN_TABLE_HEAD_1
H1_SYS_ID (primary key) | TXN_CODE | DOC_NO |
DOC_DATE
H1ID1
T1
1234
JANUARY 1, 2015
H1ID2
T70
1234
FEBRUARY 1, 2015
IN_TABLE_ITEM_1
I1_SYS_ID |
H1_SYS_ID
(foreign key referencing H1_SYS_ID in IN_TABLE_HEAD_1)
ITEM_CODE
I1ID1
H1ID1
I1
I1ID2
H1ID1
I100
I1ID3
H1ID2
I3
IN_TABLE_BATCH_1
B1_SYS_ID | TXN_CODE DOC_NO (now in IN_TABLE_HEAD_1) | BAT_NO |
B1ID1
T1
1234
B1 / can be empty
B1ID2
T70
1234
B70
IN_TABLE_HEAD_2
H2_SYS_ID (primary key) | TXN_CODE |
DOC_NO
DOC_DATE
H2ID1
T30
4567
FEBRUARY 3, 2015
H2ID2
T60
1234
JANUARY 3, 2015
IN_TABLE_ITEM_2
I2_SYS_ID | H2_SYS_ID (foreign key referencing H2_SYS_ID in IN_TABLE_HEAD_2) | ITEM_CODE |
I2ID1 | H2ID1 |
I1
I2ID2
H2ID1
I200
I2ID3
H2ID2
I2
IN_TABLE_BATCH_2
B2_SYS_ID |
I2_SYS_ID
(foreign key referencing I2_SYS_ID in IN_TABLE_ITEM_2)
BAT_NO
B2ID1
I2ID1
B30 / null
B2ID2
I2ID2
B90
B2ID2
I2ID3
B60
IN_TABLE_HEAD_3
H3_SYS_ID (primary key) | TXN_CODE | DOC_NO | DOC_DATE |
H3ID1 |
T50
1234
JANUARY 2, 2015
H3ID2
T80
1234
JANUARY 3, 2015
H3ID3
T90
1234
JANUARY 4, 2015
H3ID4
T40
1234
AUGUST 5, 2015
IN_TABLE_ITEM_3
I3_SYS_ID |
H3_SYS_ID
(foreign key referencing H3_SYS_ID in IN_TABLE_HEAD_3)
ITEM_CODE
BAT_NO
I3ID1
H31D1
I2
B50
I3ID2
H3ID2
I4
B40
I3ID3
H3ID3
I4
I3ID4
H3ID4
I6
There is no IN_TABLE_BATCH_3
Please find below the expected results.
OUTPUT
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO |
BOE_DT
BATCH_YN
I1
B1
T1
1234
JANUARY 3, 2015
THERE
I1
B30
T30
7890
FEBRUARY 5, 2015
N
I2
B60
T60
1234
JANUARY 3, 2015
N
I3
B70
T70
1234
FEBRUARY 1, 2015
THERE
I4
T90
1234
JANUARY 4, 2015
N
I6
T40
1234
AUGUST 5, 2015
N
Controls database to create the tables above and insert the records.
CREATE TABLE stock_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), boe_dt DATE );
INSERT EN stock_table
VALUES ('I1', 'B1', '', '', '');
INSERT EN stock_table
VALUES ('I1', '', '', '', '');
INSERT IN stock_table
VALUES ('I2', '', '', '', '');
INSERT EN stock_table
VALUES ('I3', 'B70', '', '', '');
INSERT EN stock_table
VALUES ('I4', 'B80', '', '', '');
INSERT EN stock_table
VALUES ('I5', 'B90', 'T102', '1234', '02-JUL-2015');
INSERT EN stock_table
VALUES ('I6', 'B100', '', '', '');
SELECT *
FROM stock_table
CREATE TABLE history_table()item_code VARCHAR2()80),bat_no VARCHAR2()80),txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), updt_dt DATE );
INSERT IN history_table
VALUES ('I1', 'B1', 'T1', '1234', '03-JAN-2015');
INSERT IN history_table
VALUES ('I1', 'B20', 'T20', '4567', '03-MAR-2015');
INSERT IN history_table
VALUES ('I1', 'B30', 'T30', '7890', '05-FEB-2015');
INSERT IN history_table
VALUES ('I2', 'B40', 'T20', '1234', '01-JAN-2015');
SELECT *
FROM history_table
CREATE TABLE transaction1()txn_code VARCHAR()80),txn_type VARCHAR()80));
INSERT INTO transaction1
VALUES ('T1', 'IN');
INSERT INTO transaction1
VALUES ('T20', 'OUT');
INSERT INTO transaction1
VALUES ('T30', 'ALL');
INSERT INTO transaction1
VALUES ('T40', 'ALL');
INSERT INTO transaction1
VALUES ('T50', 'IN');
INSERT INTO transaction1
VALUES ('T60', 'ALL');
INSERT INTO transaction1
VALUES ('T70', 'ALL');
INSERT INTO transaction1
VALUES ('T80', 'IN');
INSERT INTO transaction1
VALUES ('T90', 'IN');
SELECT *
FROM transaction1
CREATE TABLE in_table_head_1()h1_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_2()h2_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
CREATE TABLE in_table_head_3()h3_sys_id VARCHAR2()80) PRIMARY KEY,txn_code VARCHAR2()80),
doc_no VARCHAR2 (80), doc_dt DATE );
INSERT IN in_table_head_1
VALUES ('H1ID1', 'T1', '1234', '01-JAN-2015');
INSERT IN in_table_head_1
VALUES ('H1ID2', 'T70', '1234', '01-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID1', 'T30', '4567', '03-FEB-2015');
INSERT IN in_table_head_2
VALUES ('H2ID2', 'T60', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID1', 'T50', '1234', '02-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID2', 'T80', '1234', '03-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID3', 'T90', '1234', '05-JAN-2015');
INSERT IN in_table_head_3
VALUES ('H3ID4', 'T40', '1234', '05-AUG-2015');
CREATE TABLE in_table_item_1()i1_sys_id VARCHAR2()80) PRIMARY KEY,
h1_sys_id VARCHAR2 (80) REFERENCES in_table_head_1()h1_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_2()i2_sys_id VARCHAR2()80) PRIMARY KEY,
h2_sys_id VARCHAR2 (80) REFERENCES in_table_head_2()h2_sys_id),item_code VARCHAR2()80));
CREATE TABLE in_table_item_3(i3_sys_id VARCHAR2(80) PRIMARY KEY,
h3_sys_id VARCHAR2 (80) REFERENCES in_table_head_3()h3_sys_id),item_code VARCHAR2()80),
bat_no VARCHAR2 (80));
INSERT IN in_table_item_1
VALUES ('I1ID1', 'H1ID1', 'I1');
INSERT IN in_table_item_1
VALUES ('I1ID2', 'H1ID1', 'I100');
INSERT IN in_table_item_1
VALUES ('I1ID3', 'H1ID2', 'I3');
INSERT IN in_table_item_2
VALUES ('I2ID1', 'H2ID1', 'I1');
INSERT IN in_table_item_2
VALUES ('I2ID2', 'H2ID1', 'I200');
INSERT IN in_table_item_2
VALUES ('I2ID3', 'H2ID2', 'I2');
INSERT IN in_table_item_3
VALUES ('I3ID1', 'H3ID1', 'I2','B50');
INSERT IN in_table_item_3
VALUES ('I3ID2', 'H3ID2', 'I4','B40');
INSERT IN in_table_item_3
VALUES ('I3ID3', 'H3ID3', 'I4','');
INSERT IN in_table_item_3
VALUES ('I3ID4', 'H3ID4', 'I6','');
SELECT *
FROM in_table_item_1
SELECT *
FROM in_table_item_2
SELECT *
FROM in_table_item_3
CREATE TABLE in_table_batch_1()b1_sys_id VARCHAR2()80) PRIMARY KEY,
txn_code VARCHAR2 (80), doc_no VARCHAR2 (80), bat_no VARCHAR2 (80));
CREATE TABLE in_table_batch_2()b2_sys_id VARCHAR2()80) PRIMARY KEY,
i2_sys_id VARCHAR2 (80) REFERENCES in_table_item_2()i2_sys_id),bat_no VARCHAR2()80));
INSERT IN in_table_batch_1
VALUES ('B1ID1', 'T1', '1234', 'B1');
INSERT IN in_table_batch_1
VALUES ('B1ID2', 'T70', '1234', 'B70');
INSERT IN in_table_batch_2
VALUES ('B2ID1', 'I2ID1', 'B30');
INSERT IN in_table_batch_2
VALUES ('B2ID2', 'I2ID2', 'B90');
INSERT IN in_table_batch_2
VALUES ('B2ID3', 'I2ID3', 'B60');
Please advise a solution for the same.
Thank you and best regards,
Séverine Suresh
very forced (question subfactoring used to allow easy testing/verification - could work with these test data only)
with
case_1 as
(select s.item_code,
s.bat_no,
h.txn_code,
h.doc_no,
h.updt_dt boe_dt,
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 1' '.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of w_stock_table
where bat_no is null
or txn_code is null
or doc_no is null
or boe_dt is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and s.bat_no = h.bat_no
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
),
case_2 as
(select s.item_code,
NVL (s.bat_no, h.bat_no) bat_no.
NVL (s.txn_code, h.txn_code) txn_code.
NVL (s.doc_no, h.doc_no) doc_no.
NVL (s.boe_dt, h.updt_dt) updt_dt.
cases where s.bat_no = h.bat_no then 'Y' else ' n end batch_yn.
cases where h.txn_code is not null
and h.doc_no is not null
and h.updt_dt is not null
then 'case 2'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, boe_dt
of case_1
where refers_to is null
) s
left outer join
w_history_table h
On s.item_code = h.item_code
and exists (select null
of w_transaction1
where txn_code = nvl (s.txn_code, h.txn_code)
and txn_type in ('IN', 'ALL')
)
and not exists (select null
of case_1
where item_code = h.item_code
and bat_no = h.bat_no
and txn_code = h.txn_code
and doc_no = h.doc_no
and updt_dt = h.updt_dt
)
),
case_31 as
(select s1.item_code,
NVL (S1.bat_no, W1.bat_no) bat_no.
NVL (S1.txn_code, W1.txn_code) txn_code.
NVL (S1.doc_no, W1.doc_no) doc_no.
NVL (S1.updt_dt, W1.doc_dt) updt_dt.
cases where s1.bat_no = w1.bat_no then 'Y' else ' n end batch_yn.
cases where w1.txn_code is not null
and w1.doc_no is not null
and w1.doc_dt is not null
then "case 31'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s1
left outer join
(select i1.item_code, h1.txn_code, h1.doc_no, h1.doc_dt, b1.bat_no
of w_in_table_item_1 i1
inner join
w_in_table_head_1 h1
On i1.h1_sys_id = h1.h1_sys_id
inner join
w_in_table_batch_1 b1
On h1.txn_code = b1.txn_code
and h1.doc_no = b1.doc_no
) w1
On s1.item_code = w1.item_code
),
case_32 as
(select s2.item_code,
NVL (S2.bat_no, W2.bat_no) bat_no.
NVL (S2.txn_code, W2.txn_code) txn_code.
NVL (S2.doc_no, W2.doc_no) doc_no.
NVL (S2.updt_dt, W2.doc_dt) updt_dt.
cases where s2.bat_no = w2.bat_no then 'Y' else ' n end batch_yn.
cases where w2.txn_code is not null
and w2.doc_no is not null
and w2.doc_dt is not null
then "case 32'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s2
left outer join
(select i2.item_code, h2.txn_code, h2.doc_no, h2.doc_dt, b2.bat_no
of w_in_table_item_2 i2
inner join
w_in_table_head_2 h2
On i2.h2_sys_id = h2.h2_sys_id
inner join
w_in_table_batch_2 b2
On i2.i2_sys_id = b2.i2_sys_id
) w2
On s2.item_code = w2.item_code
),
case_33 as
(select s3.item_code,
w3.bat_no,
NVL (S3.txn_code, w3.txn_code) txn_code.
NVL (S3.doc_no, w3.doc_no) doc_no.
NVL (S3.updt_dt, w3.doc_dt) updt_dt.
cases where s3.bat_no = w3.bat_no then 'Y' else ' n end batch_yn.
cases where w3.txn_code is not null
and w3.doc_no is not null
and w3.doc_dt is not null
then "case 33'.
end refers_to
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn, refers_to
of case_2
where refers_to is null
) s3
left outer join
(select i3.item_code, h3.txn_code, h3.doc_no, h3.doc_dt, i3.bat_no
of w_in_table_item_3 i3
inner join
w_in_table_head_3 h3
On i3.h3_sys_id = h3.h3_sys_id
) w3
On s3.item_code = w3.item_code
)
Select item_code, bat_no, txn_code, doc_no, boe_dt, batch_yn
of case_1
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_2
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn,
ROW_NUMBER() over (partition by item_code of updt_dt desc order) rn
from (select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_31
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_32
where refers_to is not null
Union of all the
Select item_code, bat_no, txn_code, doc_no, updt_dt, batch_yn
of case_33
where refers_to is not null
)
)
where rn = 1
ITEM_CODE | BAT_NO | TXN_CODE | DOC_NO | BOE_DT | BATCH_YN |
---|---|---|---|---|---|
I1 | B1 | T1 | 1234 | JANUARY 3, 2015 | THERE |
I1 | B30 | T30 | 7890 | FEBRUARY 5, 2015 | N |
I2 | B60 | T60 | 1234 | JANUARY 3, 2015 | N |
I3 | B70 | T70 | 1234 | FEBRUARY 1, 2015 | THERE |
I4 | - | T90 | 1234 | JANUARY 5, 2015 | N |
I6 | - | T40 | 1234 | AUGUST 5, 2015 | N |
Concerning
Etbin
Maybe you are looking for
-
Photosmart 7520 paper feeding problem
I get a message that my printer needs paper when it is not. Supply works of the paper when printing directly from the printer, but not remotely. When do remotely, the printer works but no signal no matter what paper. Help!
-
Carpet * a DVD-RAM UJ-820 s does not recognize blank DVDs
My laptop recently stopped recognizing blank, or I burned when I put them in the DVD player.The drive is a CARPET * a DVD-RAM UJ-820 s and it was working fine until last week when I tried to use the ASHAMPOO Burning software. He does not even recogni
-
difference between the operational status of APs to the TOP and REG (registered)
Hello guys,. I want to know what is the difference between the operational status of APs to the TOP and REG? Thanks in advance
-
A desktop HP 1050 may throw a stand-alone Copier?
Hello Recently bought a Deskjet 1050 and really like it. My daughter needs a casual Copier for the child insurance papers, etc., but she doesn't have a computer. It seems to me that this all-in-one will be just copies by lighting it and using the cop
-
Validation of Windows 8 for downloading Windows 7 content
Hello. I want to download this free resource to Windows 7 (http://www.microsoft.com/pt-br/download/details.aspx?id=17368), but the Microsoft site forces me to validate. The problem is that the GenuineCheck.exe tool that it offers me to download does