Is there way to build logic to get one initial date of multiple entries of leaves extended further
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Emp_no | from_date | To_date | Initial_date
-------+------------+-----------+-------------
234 | 01-Dec-18 | 10-Dec-18 | 01-Dec-18
234 | 11-Dec-18 | 05-Jan-19 | 01-Dec-18
234 | 06-Jan-19 | 20-Jan-19 | 01-Dec-18
234 | 21-Jan-19 | 25-Jan-19 | 01-Dec-18
I just want to get the initial date of further extended leaves as all the entries will be treated as one initial date. How can I get the above mentioned result with column Initial_date
?
This is to add an extra functionality to calculate the total authorized or earned leave of Service in the leave management software, as in each month 4 leaves has been earned by employees with the following conditions:
- 16 days attendance is necessary in a month to earn the leaves.
- If leave connects two months so the earning of one of the month will be
lost and the earning of other month depends on the 1st condition of 16 days attendance.
So I just want to create a logic to sort out these kinds of leave which has been taken and further extended to more days which results multiple entries of continued leaves.
sql oracle plsql
add a comment |
Emp_no | from_date | To_date | Initial_date
-------+------------+-----------+-------------
234 | 01-Dec-18 | 10-Dec-18 | 01-Dec-18
234 | 11-Dec-18 | 05-Jan-19 | 01-Dec-18
234 | 06-Jan-19 | 20-Jan-19 | 01-Dec-18
234 | 21-Jan-19 | 25-Jan-19 | 01-Dec-18
I just want to get the initial date of further extended leaves as all the entries will be treated as one initial date. How can I get the above mentioned result with column Initial_date
?
This is to add an extra functionality to calculate the total authorized or earned leave of Service in the leave management software, as in each month 4 leaves has been earned by employees with the following conditions:
- 16 days attendance is necessary in a month to earn the leaves.
- If leave connects two months so the earning of one of the month will be
lost and the earning of other month depends on the 1st condition of 16 days attendance.
So I just want to create a logic to sort out these kinds of leave which has been taken and further extended to more days which results multiple entries of continued leaves.
sql oracle plsql
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. thefrom_date
of an entry is equal toTo_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date
– Hilarion
Jan 3 at 21:15
add a comment |
Emp_no | from_date | To_date | Initial_date
-------+------------+-----------+-------------
234 | 01-Dec-18 | 10-Dec-18 | 01-Dec-18
234 | 11-Dec-18 | 05-Jan-19 | 01-Dec-18
234 | 06-Jan-19 | 20-Jan-19 | 01-Dec-18
234 | 21-Jan-19 | 25-Jan-19 | 01-Dec-18
I just want to get the initial date of further extended leaves as all the entries will be treated as one initial date. How can I get the above mentioned result with column Initial_date
?
This is to add an extra functionality to calculate the total authorized or earned leave of Service in the leave management software, as in each month 4 leaves has been earned by employees with the following conditions:
- 16 days attendance is necessary in a month to earn the leaves.
- If leave connects two months so the earning of one of the month will be
lost and the earning of other month depends on the 1st condition of 16 days attendance.
So I just want to create a logic to sort out these kinds of leave which has been taken and further extended to more days which results multiple entries of continued leaves.
sql oracle plsql
Emp_no | from_date | To_date | Initial_date
-------+------------+-----------+-------------
234 | 01-Dec-18 | 10-Dec-18 | 01-Dec-18
234 | 11-Dec-18 | 05-Jan-19 | 01-Dec-18
234 | 06-Jan-19 | 20-Jan-19 | 01-Dec-18
234 | 21-Jan-19 | 25-Jan-19 | 01-Dec-18
I just want to get the initial date of further extended leaves as all the entries will be treated as one initial date. How can I get the above mentioned result with column Initial_date
?
This is to add an extra functionality to calculate the total authorized or earned leave of Service in the leave management software, as in each month 4 leaves has been earned by employees with the following conditions:
- 16 days attendance is necessary in a month to earn the leaves.
- If leave connects two months so the earning of one of the month will be
lost and the earning of other month depends on the 1st condition of 16 days attendance.
So I just want to create a logic to sort out these kinds of leave which has been taken and further extended to more days which results multiple entries of continued leaves.
sql oracle plsql
sql oracle plsql
edited Jan 4 at 1:17
Kodos Johnson
4,62942142
4,62942142
asked Jan 3 at 20:25
Basit AliBasit Ali
31
31
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. thefrom_date
of an entry is equal toTo_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date
– Hilarion
Jan 3 at 21:15
add a comment |
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. thefrom_date
of an entry is equal toTo_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date
– Hilarion
Jan 3 at 21:15
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. the
from_date
of an entry is equal to To_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date– Hilarion
Jan 3 at 21:15
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. the
from_date
of an entry is equal to To_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date– Hilarion
Jan 3 at 21:15
add a comment |
2 Answers
2
active
oldest
votes
Not sure if I understood your requirements, but let's try:
select emp_no, from_date, to_date, level lvl,
connect_by_root(from_date) initial_date
from tbl t1
start with
not exists (
select 1
from tbl t2
where t1.emp_no = t2.emp_no and t1.from_date = t2.to_date + 1)
connect by emp_no = prior emp_no and from_date = prior to_date + 1
dbfiddle demo
Using these sample data:
with tbl(emp_no, from_date, to_date) as (
select 234, date '2018-12-01', date '2018-12-10' from dual union all
select 234, date '2018-12-11', date '2019-01-05' from dual union all
select 234, date '2019-01-06', date '2019-01-20' from dual union all
select 234, date '2019-01-21', date '2019-01-25' from dual union all
-- not continuous dates
select 234, date '2019-03-10', date '2019-03-17' from dual union all
select 234, date '2019-03-18', date '2019-03-25' from dual union all
-- other emp_no
select 407, date '2018-12-15', date '2019-01-07' from dual )
... we get this result:
EMP_NO FROM_DATE TO_DATE LVL INITIAL_DATE
------ ----------- ----------- ---------- ------------
234 2018-12-01 2018-12-10 1 2018-12-01
234 2018-12-11 2019-01-05 2 2018-12-01
234 2019-01-06 2019-01-20 3 2018-12-01
234 2019-01-21 2019-01-25 4 2018-12-01
234 2019-03-10 2019-03-17 1 2019-03-10
234 2019-03-18 2019-03-25 2 2019-03-10
407 2018-12-15 2019-01-07 1 2018-12-15
If this is not what you needed please edit your question and show required output matching more complicated sample data (for instance my sample above).
Explanation: Hieriarchical query (connect by
) finds for every emp_no
dates which are not continuous and starting from these points attaches next continuous rows. Operator connect_by_root
is used to present initial_date
.
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
add a comment |
Try something along the lines of
select emp_id, from_date, to_date, (select min(from_date)
from TABLE_NAME T1
where t1.emp_id = t.emp_id) as inital_date
from TABLE_NAME T
where emp_id = 234;
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029312%2fis-there-way-to-build-logic-to-get-one-initial-date-of-multiple-entries-of-leave%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not sure if I understood your requirements, but let's try:
select emp_no, from_date, to_date, level lvl,
connect_by_root(from_date) initial_date
from tbl t1
start with
not exists (
select 1
from tbl t2
where t1.emp_no = t2.emp_no and t1.from_date = t2.to_date + 1)
connect by emp_no = prior emp_no and from_date = prior to_date + 1
dbfiddle demo
Using these sample data:
with tbl(emp_no, from_date, to_date) as (
select 234, date '2018-12-01', date '2018-12-10' from dual union all
select 234, date '2018-12-11', date '2019-01-05' from dual union all
select 234, date '2019-01-06', date '2019-01-20' from dual union all
select 234, date '2019-01-21', date '2019-01-25' from dual union all
-- not continuous dates
select 234, date '2019-03-10', date '2019-03-17' from dual union all
select 234, date '2019-03-18', date '2019-03-25' from dual union all
-- other emp_no
select 407, date '2018-12-15', date '2019-01-07' from dual )
... we get this result:
EMP_NO FROM_DATE TO_DATE LVL INITIAL_DATE
------ ----------- ----------- ---------- ------------
234 2018-12-01 2018-12-10 1 2018-12-01
234 2018-12-11 2019-01-05 2 2018-12-01
234 2019-01-06 2019-01-20 3 2018-12-01
234 2019-01-21 2019-01-25 4 2018-12-01
234 2019-03-10 2019-03-17 1 2019-03-10
234 2019-03-18 2019-03-25 2 2019-03-10
407 2018-12-15 2019-01-07 1 2018-12-15
If this is not what you needed please edit your question and show required output matching more complicated sample data (for instance my sample above).
Explanation: Hieriarchical query (connect by
) finds for every emp_no
dates which are not continuous and starting from these points attaches next continuous rows. Operator connect_by_root
is used to present initial_date
.
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
add a comment |
Not sure if I understood your requirements, but let's try:
select emp_no, from_date, to_date, level lvl,
connect_by_root(from_date) initial_date
from tbl t1
start with
not exists (
select 1
from tbl t2
where t1.emp_no = t2.emp_no and t1.from_date = t2.to_date + 1)
connect by emp_no = prior emp_no and from_date = prior to_date + 1
dbfiddle demo
Using these sample data:
with tbl(emp_no, from_date, to_date) as (
select 234, date '2018-12-01', date '2018-12-10' from dual union all
select 234, date '2018-12-11', date '2019-01-05' from dual union all
select 234, date '2019-01-06', date '2019-01-20' from dual union all
select 234, date '2019-01-21', date '2019-01-25' from dual union all
-- not continuous dates
select 234, date '2019-03-10', date '2019-03-17' from dual union all
select 234, date '2019-03-18', date '2019-03-25' from dual union all
-- other emp_no
select 407, date '2018-12-15', date '2019-01-07' from dual )
... we get this result:
EMP_NO FROM_DATE TO_DATE LVL INITIAL_DATE
------ ----------- ----------- ---------- ------------
234 2018-12-01 2018-12-10 1 2018-12-01
234 2018-12-11 2019-01-05 2 2018-12-01
234 2019-01-06 2019-01-20 3 2018-12-01
234 2019-01-21 2019-01-25 4 2018-12-01
234 2019-03-10 2019-03-17 1 2019-03-10
234 2019-03-18 2019-03-25 2 2019-03-10
407 2018-12-15 2019-01-07 1 2018-12-15
If this is not what you needed please edit your question and show required output matching more complicated sample data (for instance my sample above).
Explanation: Hieriarchical query (connect by
) finds for every emp_no
dates which are not continuous and starting from these points attaches next continuous rows. Operator connect_by_root
is used to present initial_date
.
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
add a comment |
Not sure if I understood your requirements, but let's try:
select emp_no, from_date, to_date, level lvl,
connect_by_root(from_date) initial_date
from tbl t1
start with
not exists (
select 1
from tbl t2
where t1.emp_no = t2.emp_no and t1.from_date = t2.to_date + 1)
connect by emp_no = prior emp_no and from_date = prior to_date + 1
dbfiddle demo
Using these sample data:
with tbl(emp_no, from_date, to_date) as (
select 234, date '2018-12-01', date '2018-12-10' from dual union all
select 234, date '2018-12-11', date '2019-01-05' from dual union all
select 234, date '2019-01-06', date '2019-01-20' from dual union all
select 234, date '2019-01-21', date '2019-01-25' from dual union all
-- not continuous dates
select 234, date '2019-03-10', date '2019-03-17' from dual union all
select 234, date '2019-03-18', date '2019-03-25' from dual union all
-- other emp_no
select 407, date '2018-12-15', date '2019-01-07' from dual )
... we get this result:
EMP_NO FROM_DATE TO_DATE LVL INITIAL_DATE
------ ----------- ----------- ---------- ------------
234 2018-12-01 2018-12-10 1 2018-12-01
234 2018-12-11 2019-01-05 2 2018-12-01
234 2019-01-06 2019-01-20 3 2018-12-01
234 2019-01-21 2019-01-25 4 2018-12-01
234 2019-03-10 2019-03-17 1 2019-03-10
234 2019-03-18 2019-03-25 2 2019-03-10
407 2018-12-15 2019-01-07 1 2018-12-15
If this is not what you needed please edit your question and show required output matching more complicated sample data (for instance my sample above).
Explanation: Hieriarchical query (connect by
) finds for every emp_no
dates which are not continuous and starting from these points attaches next continuous rows. Operator connect_by_root
is used to present initial_date
.
Not sure if I understood your requirements, but let's try:
select emp_no, from_date, to_date, level lvl,
connect_by_root(from_date) initial_date
from tbl t1
start with
not exists (
select 1
from tbl t2
where t1.emp_no = t2.emp_no and t1.from_date = t2.to_date + 1)
connect by emp_no = prior emp_no and from_date = prior to_date + 1
dbfiddle demo
Using these sample data:
with tbl(emp_no, from_date, to_date) as (
select 234, date '2018-12-01', date '2018-12-10' from dual union all
select 234, date '2018-12-11', date '2019-01-05' from dual union all
select 234, date '2019-01-06', date '2019-01-20' from dual union all
select 234, date '2019-01-21', date '2019-01-25' from dual union all
-- not continuous dates
select 234, date '2019-03-10', date '2019-03-17' from dual union all
select 234, date '2019-03-18', date '2019-03-25' from dual union all
-- other emp_no
select 407, date '2018-12-15', date '2019-01-07' from dual )
... we get this result:
EMP_NO FROM_DATE TO_DATE LVL INITIAL_DATE
------ ----------- ----------- ---------- ------------
234 2018-12-01 2018-12-10 1 2018-12-01
234 2018-12-11 2019-01-05 2 2018-12-01
234 2019-01-06 2019-01-20 3 2018-12-01
234 2019-01-21 2019-01-25 4 2018-12-01
234 2019-03-10 2019-03-17 1 2019-03-10
234 2019-03-18 2019-03-25 2 2019-03-10
407 2018-12-15 2019-01-07 1 2018-12-15
If this is not what you needed please edit your question and show required output matching more complicated sample data (for instance my sample above).
Explanation: Hieriarchical query (connect by
) finds for every emp_no
dates which are not continuous and starting from these points attaches next continuous rows. Operator connect_by_root
is used to present initial_date
.
answered Jan 4 at 12:31
Ponder StibbonsPonder Stibbons
9,06921519
9,06921519
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
add a comment |
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
The problem has been solved by your help thank you so much bro :)
– Basit Ali
Jan 7 at 4:21
add a comment |
Try something along the lines of
select emp_id, from_date, to_date, (select min(from_date)
from TABLE_NAME T1
where t1.emp_id = t.emp_id) as inital_date
from TABLE_NAME T
where emp_id = 234;
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
add a comment |
Try something along the lines of
select emp_id, from_date, to_date, (select min(from_date)
from TABLE_NAME T1
where t1.emp_id = t.emp_id) as inital_date
from TABLE_NAME T
where emp_id = 234;
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
add a comment |
Try something along the lines of
select emp_id, from_date, to_date, (select min(from_date)
from TABLE_NAME T1
where t1.emp_id = t.emp_id) as inital_date
from TABLE_NAME T
where emp_id = 234;
Try something along the lines of
select emp_id, from_date, to_date, (select min(from_date)
from TABLE_NAME T1
where t1.emp_id = t.emp_id) as inital_date
from TABLE_NAME T
where emp_id = 234;
answered Jan 3 at 20:59
Shaun PetersonShaun Peterson
1,1231118
1,1231118
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
add a comment |
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
Dear shaun this query will add a minimam date of all entries of individual, but we actually need the same initail date of those leave which is extended further like in table above rather then minimam of all entries.
– Basit Ali
Jan 4 at 10:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029312%2fis-there-way-to-build-logic-to-get-one-initial-date-of-multiple-entries-of-leave%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
To clarify: You consider a date as an initial date, from the set of entries, only when this is a series of consecutive leaves (i.e. the
from_date
of an entry is equal toTo_date
of another plus one) of that same employee. If that's so, you may find this question interesting: Oracle sql query to group consecutive records by date– Hilarion
Jan 3 at 21:15