Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Suvijak
Contributor
Contributor

Join table with ID and date between 2 date

Hi Friend,

I have question about script,

- I have 2 table with OrderRecord and EmployeeStatus

- I want to join those table together and with condition EmployeeID must same and Order_date must between Start date and last date

- Calculate the work experience by [Order_date - Start_date] 

- If employee have change position and change back, measure the experience from lasted time only

Input Table: OrderRecord

Order_IDOrder_dateEmployee_ID
101-Jan-192222
201-Feb-191111
301-Aug-191111
401-Aug-192222

 

EmployeeStatus

Employee_IDPositionStart_dateLast_date
1111SaleJun-19-
1111SupportMar-19Jun-19
1111SaleJan-18Jun-19
2222SaleJan-17Sep-19

* No Last date mean they still working on this position

Expected output table

Output_tableOrder_dateEmployee_IDPositionWork_experience
101-Jan-192222Sale24
201-Feb-191111Sale1
301-Aug-191111Sale2
401-Sep-192222Sale32

 

I a bit concern with performance as the OrderRecord have  more than 1M record and Employee table is around 20k record

Additional Question, I don't want to create another topic.

- Can I create sort order for every table?

- Can I join table to existing table without create new table

- If i need to load new data every time, is it needed to create QVD file?

Sorry for my poor English.

Thank you,

Suvijak.

 

1 Reply
Yousef_Amarneh
Partner - Creator III
Partner - Creator III

Hi,

For your first question, you can use intervalmatch function, just search on google and you will find good examples matching your requirements.

For the additional Question, below are the answers:

- Can I create sort order for every table?

Yes, you can use order by "field" or rowno() function and use it for sort, or you can use rank also, depends on your requirements.

- Can I join table to existing table without create new table

yes you can using join(table_name)

- If i need to load new data every time, is it needed to create QVD file?

it's good to have QVDs for all the tables specially if the table are being used in multiple applications or the data is huge and you are using incremental load, but if you need to refresh the data directly from the data source yes you can load without storing the data in QVD file.

Yousef Amarneh