sql - How to query a table to get a sequence or chain of records? -
i have table below
a user can assign tasks other user. other user in turn can assign his/her task user , on.
user assigning tasks identified task_assign_userid, , user receiving task identified task_rcv_userid.
users can assign tasks others specific period of time identified effective_date , expiration_date.
a user cannot assign task other user if other user has task in specified duration.
tasks/records filling behind current date treated inactive/completed tasks.
i want query table current active tasks given task_assign_userid. query should return record requested task_assign_userid, record if task_rcv_userid assigned task else. in turn if task_rcv_userid assigned user should return me record , on.
sample
task_assign_userid task_rcv_userid
a b
b c
c d
d e
....
....
i using db2 database. can please me? using loop in code retrieve records.
if cannot done using sql use pl/sql.
can please me?
updated:
task_assign_userid | task_rcv_user_id | effective_date | expiration_date
a | b | 10-11-2016 | 17-11-2016
b | c | 11-11-2016 | 16-11-2016
a | b | 12-11-2016 | 20-11-2016
b | c | 15-11-2016 | 18-11-2016
c | d | 15-11-2016 | 18-11-2016
should give me below, when task_assign_userid = a
task_assign_userid | task_rcv_user_id | effective_date | expiration_date
a | b | 12-11-2016 | 20-11-2016
b | c | 15-11-2016 | 18-11-2016
c | d | 15-11-2016 | 18-11-2016
should give me below, when task_assign_userid = b
task_assign_userid | task_rcv_user_id | effective_date | expiration_date
b | c | 15-11-2016 | 18-11-2016
c | d | 15-11-2016 | 18-11-2016
should give me below, when task_assign_userid = c
task_assign_userid | task_rcv_user_id | effective_date | expiration_date
c | d | 15-11-2016 | 18-11-2016
something this?
select task_assign_userid,task_rcv_user_id, max( effective_date) effective_date, max (expiration_date) expiration_date youtable group task_assign_userid,task_rcv_user_id
Comments
Post a Comment