I have fortnightly(fourteen)dates,i want op as 14 dates and amount based on deal date and maturity date












0















My question is:
i have two tables(A and B) as below



A



 deal_no deal_date deal_amnt
501 `20180525` `10`
502 `20180526` `20`
601 `20180528` `30`
602 `20180529` `40`


B



 deal_type  maturity_date
501 `20180525`
502 `20180527`
601 `20180530`
602 `20180530`


For the same deal_no(deal_type),if deal_date from A = maturity_date from B then deal_amnt for maturity_date should be same
eg(for 501--> if(20180525=20180525) then amnt=10)



For the same deal_no(deal_type),if deal_date from A < maturity_date from B then deal_amnt for maturity_date should be same,and it same amount should be upadted under deal_date

eg(for 502--> if(20180526 < 20180527) then amount for 20180527=20 and for 20180526 should also =20)



however, if i am having more than one deal_date having same maturity_date then amount for maturity_date should be sum of that two or more deal_dates.
eg(for 601 --> if(20180528 < 20180530) and for 602 --> if(20180529 < 20180530)
then amount for 20180528=30 and amount for 20180529 should =((previous 30)+(current 40))=70 and amount for 20180530 should be 70 as outstanding)



I have fortnightly(fourteen)dates,i want op as 14 dates and amount based on deal date and maturity date



op should be:



date   `deal_amnt`
20180516 0
20180517 0
20180518 0
20180519 0
20180520 0
20180521 0
20180522 0
20180523 0
20180524 0
20180525 10
20180526 20
20180527 20
20180528 30
20180529 70
20180530 70


Need help i am using plsql










share|improve this question



























    0















    My question is:
    i have two tables(A and B) as below



    A



     deal_no deal_date deal_amnt
    501 `20180525` `10`
    502 `20180526` `20`
    601 `20180528` `30`
    602 `20180529` `40`


    B



     deal_type  maturity_date
    501 `20180525`
    502 `20180527`
    601 `20180530`
    602 `20180530`


    For the same deal_no(deal_type),if deal_date from A = maturity_date from B then deal_amnt for maturity_date should be same
    eg(for 501--> if(20180525=20180525) then amnt=10)



    For the same deal_no(deal_type),if deal_date from A < maturity_date from B then deal_amnt for maturity_date should be same,and it same amount should be upadted under deal_date

    eg(for 502--> if(20180526 < 20180527) then amount for 20180527=20 and for 20180526 should also =20)



    however, if i am having more than one deal_date having same maturity_date then amount for maturity_date should be sum of that two or more deal_dates.
    eg(for 601 --> if(20180528 < 20180530) and for 602 --> if(20180529 < 20180530)
    then amount for 20180528=30 and amount for 20180529 should =((previous 30)+(current 40))=70 and amount for 20180530 should be 70 as outstanding)



    I have fortnightly(fourteen)dates,i want op as 14 dates and amount based on deal date and maturity date



    op should be:



    date   `deal_amnt`
    20180516 0
    20180517 0
    20180518 0
    20180519 0
    20180520 0
    20180521 0
    20180522 0
    20180523 0
    20180524 0
    20180525 10
    20180526 20
    20180527 20
    20180528 30
    20180529 70
    20180530 70


    Need help i am using plsql










    share|improve this question

























      0












      0








      0








      My question is:
      i have two tables(A and B) as below



      A



       deal_no deal_date deal_amnt
      501 `20180525` `10`
      502 `20180526` `20`
      601 `20180528` `30`
      602 `20180529` `40`


      B



       deal_type  maturity_date
      501 `20180525`
      502 `20180527`
      601 `20180530`
      602 `20180530`


      For the same deal_no(deal_type),if deal_date from A = maturity_date from B then deal_amnt for maturity_date should be same
      eg(for 501--> if(20180525=20180525) then amnt=10)



      For the same deal_no(deal_type),if deal_date from A < maturity_date from B then deal_amnt for maturity_date should be same,and it same amount should be upadted under deal_date

      eg(for 502--> if(20180526 < 20180527) then amount for 20180527=20 and for 20180526 should also =20)



      however, if i am having more than one deal_date having same maturity_date then amount for maturity_date should be sum of that two or more deal_dates.
      eg(for 601 --> if(20180528 < 20180530) and for 602 --> if(20180529 < 20180530)
      then amount for 20180528=30 and amount for 20180529 should =((previous 30)+(current 40))=70 and amount for 20180530 should be 70 as outstanding)



      I have fortnightly(fourteen)dates,i want op as 14 dates and amount based on deal date and maturity date



      op should be:



      date   `deal_amnt`
      20180516 0
      20180517 0
      20180518 0
      20180519 0
      20180520 0
      20180521 0
      20180522 0
      20180523 0
      20180524 0
      20180525 10
      20180526 20
      20180527 20
      20180528 30
      20180529 70
      20180530 70


      Need help i am using plsql










      share|improve this question














      My question is:
      i have two tables(A and B) as below



      A



       deal_no deal_date deal_amnt
      501 `20180525` `10`
      502 `20180526` `20`
      601 `20180528` `30`
      602 `20180529` `40`


      B



       deal_type  maturity_date
      501 `20180525`
      502 `20180527`
      601 `20180530`
      602 `20180530`


      For the same deal_no(deal_type),if deal_date from A = maturity_date from B then deal_amnt for maturity_date should be same
      eg(for 501--> if(20180525=20180525) then amnt=10)



      For the same deal_no(deal_type),if deal_date from A < maturity_date from B then deal_amnt for maturity_date should be same,and it same amount should be upadted under deal_date

      eg(for 502--> if(20180526 < 20180527) then amount for 20180527=20 and for 20180526 should also =20)



      however, if i am having more than one deal_date having same maturity_date then amount for maturity_date should be sum of that two or more deal_dates.
      eg(for 601 --> if(20180528 < 20180530) and for 602 --> if(20180529 < 20180530)
      then amount for 20180528=30 and amount for 20180529 should =((previous 30)+(current 40))=70 and amount for 20180530 should be 70 as outstanding)



      I have fortnightly(fourteen)dates,i want op as 14 dates and amount based on deal date and maturity date



      op should be:



      date   `deal_amnt`
      20180516 0
      20180517 0
      20180518 0
      20180519 0
      20180520 0
      20180521 0
      20180522 0
      20180523 0
      20180524 0
      20180525 10
      20180526 20
      20180527 20
      20180528 30
      20180529 70
      20180530 70


      Need help i am using plsql







      plsql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 12:52









      Sonam GSonam G

      32




      32
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Here's one solution purely SQL no PL needed



          SQL Fiddle



          Query 1:



          with dts(n, dt) as (
          select 1 n
          , date '2018-05-16'
          from dual
          union all
          select n+1
          , date '2018-05-16' + n
          from dts where n < 15
          )
          select dt
          , sum(deal_amnt)
          from a
          join b
          on a.deal_no = b.deal_type
          right join dts
          on dts.dt between a.deal_date and b.maturity_date
          group by dt


          Results:



          |                   DT | SUM(DEAL_AMNT) |
          |----------------------|----------------|
          | 2018-05-16T00:00:00Z | (null) |
          | 2018-05-17T00:00:00Z | (null) |
          | 2018-05-18T00:00:00Z | (null) |
          | 2018-05-19T00:00:00Z | (null) |
          | 2018-05-20T00:00:00Z | (null) |
          | 2018-05-21T00:00:00Z | (null) |
          | 2018-05-22T00:00:00Z | (null) |
          | 2018-05-23T00:00:00Z | (null) |
          | 2018-05-24T00:00:00Z | (null) |
          | 2018-05-25T00:00:00Z | 10 |
          | 2018-05-26T00:00:00Z | 20 |
          | 2018-05-27T00:00:00Z | 20 |
          | 2018-05-28T00:00:00Z | 30 |
          | 2018-05-29T00:00:00Z | 70 |
          | 2018-05-30T00:00:00Z | 70 |





          share|improve this answer

























            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958899%2fi-have-fortnightlyfourteendates-i-want-op-as-14-dates-and-amount-based-on-deal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Here's one solution purely SQL no PL needed



            SQL Fiddle



            Query 1:



            with dts(n, dt) as (
            select 1 n
            , date '2018-05-16'
            from dual
            union all
            select n+1
            , date '2018-05-16' + n
            from dts where n < 15
            )
            select dt
            , sum(deal_amnt)
            from a
            join b
            on a.deal_no = b.deal_type
            right join dts
            on dts.dt between a.deal_date and b.maturity_date
            group by dt


            Results:



            |                   DT | SUM(DEAL_AMNT) |
            |----------------------|----------------|
            | 2018-05-16T00:00:00Z | (null) |
            | 2018-05-17T00:00:00Z | (null) |
            | 2018-05-18T00:00:00Z | (null) |
            | 2018-05-19T00:00:00Z | (null) |
            | 2018-05-20T00:00:00Z | (null) |
            | 2018-05-21T00:00:00Z | (null) |
            | 2018-05-22T00:00:00Z | (null) |
            | 2018-05-23T00:00:00Z | (null) |
            | 2018-05-24T00:00:00Z | (null) |
            | 2018-05-25T00:00:00Z | 10 |
            | 2018-05-26T00:00:00Z | 20 |
            | 2018-05-27T00:00:00Z | 20 |
            | 2018-05-28T00:00:00Z | 30 |
            | 2018-05-29T00:00:00Z | 70 |
            | 2018-05-30T00:00:00Z | 70 |





            share|improve this answer






























              0














              Here's one solution purely SQL no PL needed



              SQL Fiddle



              Query 1:



              with dts(n, dt) as (
              select 1 n
              , date '2018-05-16'
              from dual
              union all
              select n+1
              , date '2018-05-16' + n
              from dts where n < 15
              )
              select dt
              , sum(deal_amnt)
              from a
              join b
              on a.deal_no = b.deal_type
              right join dts
              on dts.dt between a.deal_date and b.maturity_date
              group by dt


              Results:



              |                   DT | SUM(DEAL_AMNT) |
              |----------------------|----------------|
              | 2018-05-16T00:00:00Z | (null) |
              | 2018-05-17T00:00:00Z | (null) |
              | 2018-05-18T00:00:00Z | (null) |
              | 2018-05-19T00:00:00Z | (null) |
              | 2018-05-20T00:00:00Z | (null) |
              | 2018-05-21T00:00:00Z | (null) |
              | 2018-05-22T00:00:00Z | (null) |
              | 2018-05-23T00:00:00Z | (null) |
              | 2018-05-24T00:00:00Z | (null) |
              | 2018-05-25T00:00:00Z | 10 |
              | 2018-05-26T00:00:00Z | 20 |
              | 2018-05-27T00:00:00Z | 20 |
              | 2018-05-28T00:00:00Z | 30 |
              | 2018-05-29T00:00:00Z | 70 |
              | 2018-05-30T00:00:00Z | 70 |





              share|improve this answer




























                0












                0








                0







                Here's one solution purely SQL no PL needed



                SQL Fiddle



                Query 1:



                with dts(n, dt) as (
                select 1 n
                , date '2018-05-16'
                from dual
                union all
                select n+1
                , date '2018-05-16' + n
                from dts where n < 15
                )
                select dt
                , sum(deal_amnt)
                from a
                join b
                on a.deal_no = b.deal_type
                right join dts
                on dts.dt between a.deal_date and b.maturity_date
                group by dt


                Results:



                |                   DT | SUM(DEAL_AMNT) |
                |----------------------|----------------|
                | 2018-05-16T00:00:00Z | (null) |
                | 2018-05-17T00:00:00Z | (null) |
                | 2018-05-18T00:00:00Z | (null) |
                | 2018-05-19T00:00:00Z | (null) |
                | 2018-05-20T00:00:00Z | (null) |
                | 2018-05-21T00:00:00Z | (null) |
                | 2018-05-22T00:00:00Z | (null) |
                | 2018-05-23T00:00:00Z | (null) |
                | 2018-05-24T00:00:00Z | (null) |
                | 2018-05-25T00:00:00Z | 10 |
                | 2018-05-26T00:00:00Z | 20 |
                | 2018-05-27T00:00:00Z | 20 |
                | 2018-05-28T00:00:00Z | 30 |
                | 2018-05-29T00:00:00Z | 70 |
                | 2018-05-30T00:00:00Z | 70 |





                share|improve this answer















                Here's one solution purely SQL no PL needed



                SQL Fiddle



                Query 1:



                with dts(n, dt) as (
                select 1 n
                , date '2018-05-16'
                from dual
                union all
                select n+1
                , date '2018-05-16' + n
                from dts where n < 15
                )
                select dt
                , sum(deal_amnt)
                from a
                join b
                on a.deal_no = b.deal_type
                right join dts
                on dts.dt between a.deal_date and b.maturity_date
                group by dt


                Results:



                |                   DT | SUM(DEAL_AMNT) |
                |----------------------|----------------|
                | 2018-05-16T00:00:00Z | (null) |
                | 2018-05-17T00:00:00Z | (null) |
                | 2018-05-18T00:00:00Z | (null) |
                | 2018-05-19T00:00:00Z | (null) |
                | 2018-05-20T00:00:00Z | (null) |
                | 2018-05-21T00:00:00Z | (null) |
                | 2018-05-22T00:00:00Z | (null) |
                | 2018-05-23T00:00:00Z | (null) |
                | 2018-05-24T00:00:00Z | (null) |
                | 2018-05-25T00:00:00Z | 10 |
                | 2018-05-26T00:00:00Z | 20 |
                | 2018-05-27T00:00:00Z | 20 |
                | 2018-05-28T00:00:00Z | 30 |
                | 2018-05-29T00:00:00Z | 70 |
                | 2018-05-30T00:00:00Z | 70 |






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 28 '18 at 21:14

























                answered Dec 28 '18 at 19:59









                SentinelSentinel

                4,53611120




                4,53611120






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958899%2fi-have-fortnightlyfourteendates-i-want-op-as-14-dates-and-amount-based-on-deal%23new-answer', 'question_page');
                    }
                    );

                    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







                    Popular posts from this blog

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas

                    Can't read property showImagePicker of undefined in react native iOS