SQL query to count data from two columns (combined) of the table












-2














Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?



data



For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:



result



and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:



result2










share|improve this question





























    -2














    Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?



    data



    For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:



    result



    and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:



    result2










    share|improve this question



























      -2












      -2








      -2







      Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?



      data



      For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:



      result



      and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:



      result2










      share|improve this question















      Is there any SQL query which counts the total number of data combined from two or three columns and displays the total?



      data



      For example in the given table, column A has 1 and Column B has 2 so the result of the query should be:



      result



      and what could be SQL query if column A and B are common(repeating) but C has distinct data? Result should be:



      result2







      mysql sql excel database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 4:03

























      asked Nov 21 at 0:27









      Krin

      13




      13
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Grouping on A,B and counting the results:



          SELECT A,B, COUNT(*) as Total
          FROM table
          GROUP BY A,B





          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:05










          • If C is distinct, which row should be selected?
            – danblack
            Nov 21 at 4:11










          • So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
            – Krin
            Nov 21 at 4:21










          • Append C to the GROUP BY list and to the SELECT results.
            – danblack
            Nov 21 at 4:24






          • 1




            @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
            – Madhur Bhaiya
            Nov 21 at 5:02



















          0














          select A, B, count(*)
          from TABLE
          group by A, B






          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:04



















          0














          SELECT
          A
          , B
          , COUNT(*)
          , COUNT(DISTINCT C)
          FROM
          table
          GROUP BY
          A
          , B





          share|improve this answer





















          • Thanks worked well with what I was expecting.
            – Krin
            Nov 21 at 15:08











          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%2f53403629%2fsql-query-to-count-data-from-two-columns-combined-of-the-table%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Grouping on A,B and counting the results:



          SELECT A,B, COUNT(*) as Total
          FROM table
          GROUP BY A,B





          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:05










          • If C is distinct, which row should be selected?
            – danblack
            Nov 21 at 4:11










          • So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
            – Krin
            Nov 21 at 4:21










          • Append C to the GROUP BY list and to the SELECT results.
            – danblack
            Nov 21 at 4:24






          • 1




            @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
            – Madhur Bhaiya
            Nov 21 at 5:02
















          1














          Grouping on A,B and counting the results:



          SELECT A,B, COUNT(*) as Total
          FROM table
          GROUP BY A,B





          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:05










          • If C is distinct, which row should be selected?
            – danblack
            Nov 21 at 4:11










          • So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
            – Krin
            Nov 21 at 4:21










          • Append C to the GROUP BY list and to the SELECT results.
            – danblack
            Nov 21 at 4:24






          • 1




            @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
            – Madhur Bhaiya
            Nov 21 at 5:02














          1












          1








          1






          Grouping on A,B and counting the results:



          SELECT A,B, COUNT(*) as Total
          FROM table
          GROUP BY A,B





          share|improve this answer












          Grouping on A,B and counting the results:



          SELECT A,B, COUNT(*) as Total
          FROM table
          GROUP BY A,B






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 0:48









          danblack

          1,5071214




          1,5071214












          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:05










          • If C is distinct, which row should be selected?
            – danblack
            Nov 21 at 4:11










          • So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
            – Krin
            Nov 21 at 4:21










          • Append C to the GROUP BY list and to the SELECT results.
            – danblack
            Nov 21 at 4:24






          • 1




            @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
            – Madhur Bhaiya
            Nov 21 at 5:02


















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:05










          • If C is distinct, which row should be selected?
            – danblack
            Nov 21 at 4:11










          • So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
            – Krin
            Nov 21 at 4:21










          • Append C to the GROUP BY list and to the SELECT results.
            – danblack
            Nov 21 at 4:24






          • 1




            @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
            – Madhur Bhaiya
            Nov 21 at 5:02
















          Updated the question, if you can help me with that. Thanks.
          – Krin
          Nov 21 at 4:05




          Updated the question, if you can help me with that. Thanks.
          – Krin
          Nov 21 at 4:05












          If C is distinct, which row should be selected?
          – danblack
          Nov 21 at 4:11




          If C is distinct, which row should be selected?
          – danblack
          Nov 21 at 4:11












          So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
          – Krin
          Nov 21 at 4:21




          So, it is same as solution you gave, the added criteria is if we take column C in account(which has different data value), how many distinct data are there in column C with combination of A, B repeating. Hope I explained it properly.
          – Krin
          Nov 21 at 4:21












          Append C to the GROUP BY list and to the SELECT results.
          – danblack
          Nov 21 at 4:24




          Append C to the GROUP BY list and to the SELECT results.
          – danblack
          Nov 21 at 4:24




          1




          1




          @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
          – Madhur Bhaiya
          Nov 21 at 5:02




          @Krin dont change the question considerably, once you have received answers for the original question. You should consider marking the best answer as accepted answer, and post a new question instead. Please see: How to accept an answer for closure. You get points for it as well. Thanks :)
          – Madhur Bhaiya
          Nov 21 at 5:02













          0














          select A, B, count(*)
          from TABLE
          group by A, B






          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:04
















          0














          select A, B, count(*)
          from TABLE
          group by A, B






          share|improve this answer





















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:04














          0












          0








          0






          select A, B, count(*)
          from TABLE
          group by A, B






          share|improve this answer












          select A, B, count(*)
          from TABLE
          group by A, B







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 0:49









          Michal Rosa

          1,3061814




          1,3061814












          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:04


















          • Updated the question, if you can help me with that. Thanks.
            – Krin
            Nov 21 at 4:04
















          Updated the question, if you can help me with that. Thanks.
          – Krin
          Nov 21 at 4:04




          Updated the question, if you can help me with that. Thanks.
          – Krin
          Nov 21 at 4:04











          0














          SELECT
          A
          , B
          , COUNT(*)
          , COUNT(DISTINCT C)
          FROM
          table
          GROUP BY
          A
          , B





          share|improve this answer





















          • Thanks worked well with what I was expecting.
            – Krin
            Nov 21 at 15:08
















          0














          SELECT
          A
          , B
          , COUNT(*)
          , COUNT(DISTINCT C)
          FROM
          table
          GROUP BY
          A
          , B





          share|improve this answer





















          • Thanks worked well with what I was expecting.
            – Krin
            Nov 21 at 15:08














          0












          0








          0






          SELECT
          A
          , B
          , COUNT(*)
          , COUNT(DISTINCT C)
          FROM
          table
          GROUP BY
          A
          , B





          share|improve this answer












          SELECT
          A
          , B
          , COUNT(*)
          , COUNT(DISTINCT C)
          FROM
          table
          GROUP BY
          A
          , B






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 4:22









          fifonik

          38518




          38518












          • Thanks worked well with what I was expecting.
            – Krin
            Nov 21 at 15:08


















          • Thanks worked well with what I was expecting.
            – Krin
            Nov 21 at 15:08
















          Thanks worked well with what I was expecting.
          – Krin
          Nov 21 at 15:08




          Thanks worked well with what I was expecting.
          – Krin
          Nov 21 at 15:08


















          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%2f53403629%2fsql-query-to-count-data-from-two-columns-combined-of-the-table%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

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'