Oracle SQL - How to aggregate rows with the same value in one column











up vote
-2
down vote

favorite












I need help. Have done this when using aggregating functions but since I am not using them here don`t know how to do it.



ID num1 num2 num3 num4



180919113541070 0 0 0 4



180919113541070 0 0 0 0



180919113541070 4 0 0 0



this is a simple select
select *
from tableX
order by ID;



I would like this data to appear in one row as below:



ID num1 num2 num3 num4



180919113541070 4 0 0 4



and not even have rows where all are 0.



Thank you!










share|improve this question


























    up vote
    -2
    down vote

    favorite












    I need help. Have done this when using aggregating functions but since I am not using them here don`t know how to do it.



    ID num1 num2 num3 num4



    180919113541070 0 0 0 4



    180919113541070 0 0 0 0



    180919113541070 4 0 0 0



    this is a simple select
    select *
    from tableX
    order by ID;



    I would like this data to appear in one row as below:



    ID num1 num2 num3 num4



    180919113541070 4 0 0 4



    and not even have rows where all are 0.



    Thank you!










    share|improve this question
























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I need help. Have done this when using aggregating functions but since I am not using them here don`t know how to do it.



      ID num1 num2 num3 num4



      180919113541070 0 0 0 4



      180919113541070 0 0 0 0



      180919113541070 4 0 0 0



      this is a simple select
      select *
      from tableX
      order by ID;



      I would like this data to appear in one row as below:



      ID num1 num2 num3 num4



      180919113541070 4 0 0 4



      and not even have rows where all are 0.



      Thank you!










      share|improve this question













      I need help. Have done this when using aggregating functions but since I am not using them here don`t know how to do it.



      ID num1 num2 num3 num4



      180919113541070 0 0 0 4



      180919113541070 0 0 0 0



      180919113541070 4 0 0 0



      this is a simple select
      select *
      from tableX
      order by ID;



      I would like this data to appear in one row as below:



      ID num1 num2 num3 num4



      180919113541070 4 0 0 4



      and not even have rows where all are 0.



      Thank you!







      sql oracle oracle-sqldeveloper






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 16:41









      bobypoz

      11




      11
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          use aggregate function



          select id,sum(num1) num1,sum(num2) num2,
          sum(num3) num3,sum(num4) num4 from t group by id





          share|improve this answer





















          • Perfect!! Thank you. Easy
            – bobypoz
            Nov 22 at 17:23










          • @bobypoz stackoverflow.com/help/someone-answers
            – Zaynul Abadin Tuhin
            Nov 22 at 17:40


















          up vote
          0
          down vote













          You seem to want simple aggregation:



          select id, max(num1) as num1, max(num2) as num2, max(num3) as num3, max(num4) as num4
          from t
          group by id;





          share|improve this answer





















          • Thank you!! Should`ve realized this myself but you helped a lot.
            – bobypoz
            Nov 22 at 17:24











          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%2f53435225%2foracle-sql-how-to-aggregate-rows-with-the-same-value-in-one-column%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








          up vote
          1
          down vote













          use aggregate function



          select id,sum(num1) num1,sum(num2) num2,
          sum(num3) num3,sum(num4) num4 from t group by id





          share|improve this answer





















          • Perfect!! Thank you. Easy
            – bobypoz
            Nov 22 at 17:23










          • @bobypoz stackoverflow.com/help/someone-answers
            – Zaynul Abadin Tuhin
            Nov 22 at 17:40















          up vote
          1
          down vote













          use aggregate function



          select id,sum(num1) num1,sum(num2) num2,
          sum(num3) num3,sum(num4) num4 from t group by id





          share|improve this answer





















          • Perfect!! Thank you. Easy
            – bobypoz
            Nov 22 at 17:23










          • @bobypoz stackoverflow.com/help/someone-answers
            – Zaynul Abadin Tuhin
            Nov 22 at 17:40













          up vote
          1
          down vote










          up vote
          1
          down vote









          use aggregate function



          select id,sum(num1) num1,sum(num2) num2,
          sum(num3) num3,sum(num4) num4 from t group by id





          share|improve this answer












          use aggregate function



          select id,sum(num1) num1,sum(num2) num2,
          sum(num3) num3,sum(num4) num4 from t group by id






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 16:43









          Zaynul Abadin Tuhin

          11.2k2831




          11.2k2831












          • Perfect!! Thank you. Easy
            – bobypoz
            Nov 22 at 17:23










          • @bobypoz stackoverflow.com/help/someone-answers
            – Zaynul Abadin Tuhin
            Nov 22 at 17:40


















          • Perfect!! Thank you. Easy
            – bobypoz
            Nov 22 at 17:23










          • @bobypoz stackoverflow.com/help/someone-answers
            – Zaynul Abadin Tuhin
            Nov 22 at 17:40
















          Perfect!! Thank you. Easy
          – bobypoz
          Nov 22 at 17:23




          Perfect!! Thank you. Easy
          – bobypoz
          Nov 22 at 17:23












          @bobypoz stackoverflow.com/help/someone-answers
          – Zaynul Abadin Tuhin
          Nov 22 at 17:40




          @bobypoz stackoverflow.com/help/someone-answers
          – Zaynul Abadin Tuhin
          Nov 22 at 17:40












          up vote
          0
          down vote













          You seem to want simple aggregation:



          select id, max(num1) as num1, max(num2) as num2, max(num3) as num3, max(num4) as num4
          from t
          group by id;





          share|improve this answer





















          • Thank you!! Should`ve realized this myself but you helped a lot.
            – bobypoz
            Nov 22 at 17:24















          up vote
          0
          down vote













          You seem to want simple aggregation:



          select id, max(num1) as num1, max(num2) as num2, max(num3) as num3, max(num4) as num4
          from t
          group by id;





          share|improve this answer





















          • Thank you!! Should`ve realized this myself but you helped a lot.
            – bobypoz
            Nov 22 at 17:24













          up vote
          0
          down vote










          up vote
          0
          down vote









          You seem to want simple aggregation:



          select id, max(num1) as num1, max(num2) as num2, max(num3) as num3, max(num4) as num4
          from t
          group by id;





          share|improve this answer












          You seem to want simple aggregation:



          select id, max(num1) as num1, max(num2) as num2, max(num3) as num3, max(num4) as num4
          from t
          group by id;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 16:43









          Gordon Linoff

          754k35289397




          754k35289397












          • Thank you!! Should`ve realized this myself but you helped a lot.
            – bobypoz
            Nov 22 at 17:24


















          • Thank you!! Should`ve realized this myself but you helped a lot.
            – bobypoz
            Nov 22 at 17:24
















          Thank you!! Should`ve realized this myself but you helped a lot.
          – bobypoz
          Nov 22 at 17:24




          Thank you!! Should`ve realized this myself but you helped a lot.
          – bobypoz
          Nov 22 at 17:24


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53435225%2foracle-sql-how-to-aggregate-rows-with-the-same-value-in-one-column%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

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)