Retrieve Dates from Different Rows

  • Hi,

    I need to retrieve dates (and other fields) from different rows.  How do I accomplish this?

    Data looks like:

    plan_numcall_numpackage_numcompleted_datenext_scheduled_datejob_id
    1234561120130112201512311000000
    1234562120140224201603171000000
    1234563120141213201702021000000
    1234564120150917201711211000000
    1234565100000000201811211000000
    7890121120150713201512291000000
    7890122120160821201607081000000
    7890123100000000201708241000000

    The user will type in the job_id.  I need to return plan_num, package_num, the most recent completed date and the scheduled date from the row following the most recent completed date.  So, in this case, the user will type in job_id 1000000 and I need to return all of the following:

    123456 1 20150917 20181121
    789012 1 20160821 20170824

    Thank you!

  • wenger.noah - Thursday, January 19, 2017 5:35 AM

    Hi,

    I need to retrieve dates (and other fields) from different rows.  How do I accomplish this?

    Data looks like:

    plan_numcall_numpackage_numcompleted_datenext_scheduled_datejob_id
    1234561120130112201512311000000
    1234562120140224201603171000000
    1234563120141213201702021000000
    1234564120150917201711211000000
    1234565100000000201811211000000
    7890121120150713201512291000000
    7890122120160821201607081000000
    7890123100000000201708241000000

    The user will type in the job_id.  I need to return plan_num, package_num, the most recent completed date and the scheduled date from the row following the most recent completed date.  So, in this case, the user will type in job_id 1000000 and I need to return all of the following:

    123456 1 20150917 20181121
    789012 1 20160821 20170824

    Thank you!

    You can use the LAG and LEAD windowing functions.

    John

  • wenger.noah - Thursday, January 19, 2017 5:35 AM

    Hi,

    I need to retrieve dates (and other fields) from different rows.  How do I accomplish this?

    Data looks like:

    plan_numcall_numpackage_numcompleted_datenext_scheduled_datejob_id
    1234561120130112201512311000000
    1234562120140224201603171000000
    1234563120141213201702021000000
    1234564120150917201711211000000
    1234565100000000201811211000000
    7890121120150713201512291000000
    7890122120160821201607081000000
    7890123100000000201708241000000

    The user will type in the job_id.  I need to return plan_num, package_num, the most recent completed date and the scheduled date from the row following the most recent completed date.  So, in this case, the user will type in job_id 1000000 and I need to return all of the following:

    123456 1 20150917 20181121
    789012 1 20160821 20170824

    Thank you!

    It looks obvious, but you did not mention it: do the returned results need to contain one row per discrete plan_num, for the selected job_id?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Phil Parkin - Thursday, January 19, 2017 5:49 AM

    wenger.noah - Thursday, January 19, 2017 5:35 AM

    Hi,

    I need to retrieve dates (and other fields) from different rows.  How do I accomplish this?

    Data looks like:

    plan_numcall_numpackage_numcompleted_datenext_scheduled_datejob_id
    1234561120130112201512311000000
    1234562120140224201603171000000
    1234563120141213201702021000000
    1234564120150917201711211000000
    1234565100000000201811211000000
    7890121120150713201512291000000
    7890122120160821201607081000000
    7890123100000000201708241000000

    The user will type in the job_id.  I need to return plan_num, package_num, the most recent completed date and the scheduled date from the row following the most recent completed date.  So, in this case, the user will type in job_id 1000000 and I need to return all of the following:

    123456 1 20150917 20181121
    789012 1 20160821 20170824

    Thank you!

    It looks obvious, but you did not mention it: do the returned results need to contain one row per discrete plan_num, for the selected job_id?

    yes - one row per discrete plan_num for selected job_id

  • wenger.noah - Thursday, January 19, 2017 7:13 AM

    Phil Parkin - Thursday, January 19, 2017 5:49 AM

    wenger.noah - Thursday, January 19, 2017 5:35 AM

    Hi,

    I need to retrieve dates (and other fields) from different rows.  How do I accomplish this?

    Data looks like:

    plan_numcall_numpackage_numcompleted_datenext_scheduled_datejob_id
    1234561120130112201512311000000
    1234562120140224201603171000000
    1234563120141213201702021000000
    1234564120150917201711211000000
    1234565100000000201811211000000
    7890121120150713201512291000000
    7890122120160821201607081000000
    7890123100000000201708241000000

    The user will type in the job_id.  I need to return plan_num, package_num, the most recent completed date and the scheduled date from the row following the most recent completed date.  So, in this case, the user will type in job_id 1000000 and I need to return all of the following:

    123456 1 20150917 20181121
    789012 1 20160821 20170824

    Thank you!

    It looks obvious, but you did not mention it: do the returned results need to contain one row per discrete plan_num, for the selected job_id?

    yes - one row per discrete plan_num for selected job_id

    I figured it out, but if you want to post your solution, it might help be QA

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply