SQL Get the total count of registered user in day by day












-2














Can you help me to construct a query. The scenario is this, I want to get the total value of the registered users each day.










share|improve this question




















  • 2




    provide your expected output and sample data
    – fa06
    Oct 8 '18 at 4:55










  • Where is your sample data?
    – Noor A Shuvo
    Oct 8 '18 at 5:10










  • Hello there! I've updated my post. I include that sample and output data
    – CAR
    Oct 8 '18 at 5:52










  • Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
    – CAR
    Oct 8 '18 at 6:00






  • 1




    Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
    – a_horse_with_no_name
    Oct 8 '18 at 6:00
















-2














Can you help me to construct a query. The scenario is this, I want to get the total value of the registered users each day.










share|improve this question




















  • 2




    provide your expected output and sample data
    – fa06
    Oct 8 '18 at 4:55










  • Where is your sample data?
    – Noor A Shuvo
    Oct 8 '18 at 5:10










  • Hello there! I've updated my post. I include that sample and output data
    – CAR
    Oct 8 '18 at 5:52










  • Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
    – CAR
    Oct 8 '18 at 6:00






  • 1




    Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
    – a_horse_with_no_name
    Oct 8 '18 at 6:00














-2












-2








-2







Can you help me to construct a query. The scenario is this, I want to get the total value of the registered users each day.










share|improve this question















Can you help me to construct a query. The scenario is this, I want to get the total value of the registered users each day.







mysql sql mysqli pivot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:46

























asked Oct 8 '18 at 4:54









CAR

13




13








  • 2




    provide your expected output and sample data
    – fa06
    Oct 8 '18 at 4:55










  • Where is your sample data?
    – Noor A Shuvo
    Oct 8 '18 at 5:10










  • Hello there! I've updated my post. I include that sample and output data
    – CAR
    Oct 8 '18 at 5:52










  • Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
    – CAR
    Oct 8 '18 at 6:00






  • 1




    Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
    – a_horse_with_no_name
    Oct 8 '18 at 6:00














  • 2




    provide your expected output and sample data
    – fa06
    Oct 8 '18 at 4:55










  • Where is your sample data?
    – Noor A Shuvo
    Oct 8 '18 at 5:10










  • Hello there! I've updated my post. I include that sample and output data
    – CAR
    Oct 8 '18 at 5:52










  • Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
    – CAR
    Oct 8 '18 at 6:00






  • 1




    Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
    – a_horse_with_no_name
    Oct 8 '18 at 6:00








2




2




provide your expected output and sample data
– fa06
Oct 8 '18 at 4:55




provide your expected output and sample data
– fa06
Oct 8 '18 at 4:55












Where is your sample data?
– Noor A Shuvo
Oct 8 '18 at 5:10




Where is your sample data?
– Noor A Shuvo
Oct 8 '18 at 5:10












Hello there! I've updated my post. I include that sample and output data
– CAR
Oct 8 '18 at 5:52




Hello there! I've updated my post. I include that sample and output data
– CAR
Oct 8 '18 at 5:52












Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
– CAR
Oct 8 '18 at 6:00




Sorry the output is wrong i want it day by day for a week maybe. Example This monday until Sunday
– CAR
Oct 8 '18 at 6:00




1




1




Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
– a_horse_with_no_name
Oct 8 '18 at 6:00




Which DBMS product are you using? "SQL" is just a query language, not the name of a specific database product. Please add a tag for the database product you are using postgresql, oracle, sql-server, db2, ...
– a_horse_with_no_name
Oct 8 '18 at 6:00












4 Answers
4






active

oldest

votes


















0














Select  count(*) 
from tableName
Where registered = true
Group by Date





share|improve this answer





























    0














    Assuming that your registration timestamp is stored at created_at date-time field and table named say user:



    SELECT created_at,COUNT(*) as `total registration` FROM `user` GROUP BY (DATE(`user`.`created_at`))





    share|improve this answer





























      0














      The former answers do neither cover the where part nor output the dayname.



      This should do both and produce what you want:



      create table #data (
      reg_id int,
      reg_email nvarchar(255),
      reg_date datetimeoffset(7)
      )

      insert into #data(reg_id, reg_email, reg_date)
      VALUES
      (1, 'a', '2018-10-01'),
      (2, 'b', '2018-10-01'),
      (3, 'c', '2018-10-02'),
      (4, 'd', '2018-10-03'),
      (5, 'e', '2018-10-01'),
      (6, 'f', '2018-10-02'),
      (7, 'g', '2018-10-04'),
      (8, 'h', '2018-10-05'),
      (9, 'i', '2018-10-05'),
      (10, 'j', '2018-10-06')

      SELECT count(*), datename(dw, reg_date) from #data
      where datepart(week, reg_date) = 40
      group by reg_date

      drop table #data


      assuming that you are using sql server greater or equal 2008!






      share|improve this answer





























        0














        I finally get the correct data for today and last 7 days. Please refer below query.



        SELECT 
        a.JourneyName,
        a.BonusName,
        a.Status,
        a."Timestamp",
        a.MID,
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 0 THEN 1 ELSE NULL END) as "Day_1",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 1 THEN 1 ELSE NULL END) as "Day_2",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 2 THEN 1 ELSE NULL END) as "Day_3",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 3 THEN 1 ELSE NULL END) as "Day_4",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 4 THEN 1 ELSE NULL END) as "Day_5",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 5 THEN 1 ELSE NULL END) as "Day_6",
        COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 6 THEN 1 ELSE NULL END) as "Day_7"
        FROM
        TableName a
        WHERE
        a."Timestamp" >= DATEADD(DD, -7, GETDATE())
        AND a."Timestamp" <= GETDATE()
        GROUP BY``
        a.JourneyName, a.BonusName, a.Status, a."Timestamp", a.MID


        Total Count per day where Day_1 is today, Day_2 is yesterday and so on.






        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%2f52695588%2fsql-get-the-total-count-of-registered-user-in-day-by-day%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Select  count(*) 
          from tableName
          Where registered = true
          Group by Date





          share|improve this answer


























            0














            Select  count(*) 
            from tableName
            Where registered = true
            Group by Date





            share|improve this answer
























              0












              0








              0






              Select  count(*) 
              from tableName
              Where registered = true
              Group by Date





              share|improve this answer












              Select  count(*) 
              from tableName
              Where registered = true
              Group by Date






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 8 '18 at 5:00









              PrathapG

              534418




              534418

























                  0














                  Assuming that your registration timestamp is stored at created_at date-time field and table named say user:



                  SELECT created_at,COUNT(*) as `total registration` FROM `user` GROUP BY (DATE(`user`.`created_at`))





                  share|improve this answer


























                    0














                    Assuming that your registration timestamp is stored at created_at date-time field and table named say user:



                    SELECT created_at,COUNT(*) as `total registration` FROM `user` GROUP BY (DATE(`user`.`created_at`))





                    share|improve this answer
























                      0












                      0








                      0






                      Assuming that your registration timestamp is stored at created_at date-time field and table named say user:



                      SELECT created_at,COUNT(*) as `total registration` FROM `user` GROUP BY (DATE(`user`.`created_at`))





                      share|improve this answer












                      Assuming that your registration timestamp is stored at created_at date-time field and table named say user:



                      SELECT created_at,COUNT(*) as `total registration` FROM `user` GROUP BY (DATE(`user`.`created_at`))






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Oct 8 '18 at 5:02









                      Pratik Karmakar

                      22118




                      22118























                          0














                          The former answers do neither cover the where part nor output the dayname.



                          This should do both and produce what you want:



                          create table #data (
                          reg_id int,
                          reg_email nvarchar(255),
                          reg_date datetimeoffset(7)
                          )

                          insert into #data(reg_id, reg_email, reg_date)
                          VALUES
                          (1, 'a', '2018-10-01'),
                          (2, 'b', '2018-10-01'),
                          (3, 'c', '2018-10-02'),
                          (4, 'd', '2018-10-03'),
                          (5, 'e', '2018-10-01'),
                          (6, 'f', '2018-10-02'),
                          (7, 'g', '2018-10-04'),
                          (8, 'h', '2018-10-05'),
                          (9, 'i', '2018-10-05'),
                          (10, 'j', '2018-10-06')

                          SELECT count(*), datename(dw, reg_date) from #data
                          where datepart(week, reg_date) = 40
                          group by reg_date

                          drop table #data


                          assuming that you are using sql server greater or equal 2008!






                          share|improve this answer


























                            0














                            The former answers do neither cover the where part nor output the dayname.



                            This should do both and produce what you want:



                            create table #data (
                            reg_id int,
                            reg_email nvarchar(255),
                            reg_date datetimeoffset(7)
                            )

                            insert into #data(reg_id, reg_email, reg_date)
                            VALUES
                            (1, 'a', '2018-10-01'),
                            (2, 'b', '2018-10-01'),
                            (3, 'c', '2018-10-02'),
                            (4, 'd', '2018-10-03'),
                            (5, 'e', '2018-10-01'),
                            (6, 'f', '2018-10-02'),
                            (7, 'g', '2018-10-04'),
                            (8, 'h', '2018-10-05'),
                            (9, 'i', '2018-10-05'),
                            (10, 'j', '2018-10-06')

                            SELECT count(*), datename(dw, reg_date) from #data
                            where datepart(week, reg_date) = 40
                            group by reg_date

                            drop table #data


                            assuming that you are using sql server greater or equal 2008!






                            share|improve this answer
























                              0












                              0








                              0






                              The former answers do neither cover the where part nor output the dayname.



                              This should do both and produce what you want:



                              create table #data (
                              reg_id int,
                              reg_email nvarchar(255),
                              reg_date datetimeoffset(7)
                              )

                              insert into #data(reg_id, reg_email, reg_date)
                              VALUES
                              (1, 'a', '2018-10-01'),
                              (2, 'b', '2018-10-01'),
                              (3, 'c', '2018-10-02'),
                              (4, 'd', '2018-10-03'),
                              (5, 'e', '2018-10-01'),
                              (6, 'f', '2018-10-02'),
                              (7, 'g', '2018-10-04'),
                              (8, 'h', '2018-10-05'),
                              (9, 'i', '2018-10-05'),
                              (10, 'j', '2018-10-06')

                              SELECT count(*), datename(dw, reg_date) from #data
                              where datepart(week, reg_date) = 40
                              group by reg_date

                              drop table #data


                              assuming that you are using sql server greater or equal 2008!






                              share|improve this answer












                              The former answers do neither cover the where part nor output the dayname.



                              This should do both and produce what you want:



                              create table #data (
                              reg_id int,
                              reg_email nvarchar(255),
                              reg_date datetimeoffset(7)
                              )

                              insert into #data(reg_id, reg_email, reg_date)
                              VALUES
                              (1, 'a', '2018-10-01'),
                              (2, 'b', '2018-10-01'),
                              (3, 'c', '2018-10-02'),
                              (4, 'd', '2018-10-03'),
                              (5, 'e', '2018-10-01'),
                              (6, 'f', '2018-10-02'),
                              (7, 'g', '2018-10-04'),
                              (8, 'h', '2018-10-05'),
                              (9, 'i', '2018-10-05'),
                              (10, 'j', '2018-10-06')

                              SELECT count(*), datename(dw, reg_date) from #data
                              where datepart(week, reg_date) = 40
                              group by reg_date

                              drop table #data


                              assuming that you are using sql server greater or equal 2008!







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Oct 8 '18 at 6:23









                              Josef Biehler

                              15710




                              15710























                                  0














                                  I finally get the correct data for today and last 7 days. Please refer below query.



                                  SELECT 
                                  a.JourneyName,
                                  a.BonusName,
                                  a.Status,
                                  a."Timestamp",
                                  a.MID,
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 0 THEN 1 ELSE NULL END) as "Day_1",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 1 THEN 1 ELSE NULL END) as "Day_2",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 2 THEN 1 ELSE NULL END) as "Day_3",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 3 THEN 1 ELSE NULL END) as "Day_4",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 4 THEN 1 ELSE NULL END) as "Day_5",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 5 THEN 1 ELSE NULL END) as "Day_6",
                                  COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 6 THEN 1 ELSE NULL END) as "Day_7"
                                  FROM
                                  TableName a
                                  WHERE
                                  a."Timestamp" >= DATEADD(DD, -7, GETDATE())
                                  AND a."Timestamp" <= GETDATE()
                                  GROUP BY``
                                  a.JourneyName, a.BonusName, a.Status, a."Timestamp", a.MID


                                  Total Count per day where Day_1 is today, Day_2 is yesterday and so on.






                                  share|improve this answer




























                                    0














                                    I finally get the correct data for today and last 7 days. Please refer below query.



                                    SELECT 
                                    a.JourneyName,
                                    a.BonusName,
                                    a.Status,
                                    a."Timestamp",
                                    a.MID,
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 0 THEN 1 ELSE NULL END) as "Day_1",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 1 THEN 1 ELSE NULL END) as "Day_2",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 2 THEN 1 ELSE NULL END) as "Day_3",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 3 THEN 1 ELSE NULL END) as "Day_4",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 4 THEN 1 ELSE NULL END) as "Day_5",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 5 THEN 1 ELSE NULL END) as "Day_6",
                                    COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 6 THEN 1 ELSE NULL END) as "Day_7"
                                    FROM
                                    TableName a
                                    WHERE
                                    a."Timestamp" >= DATEADD(DD, -7, GETDATE())
                                    AND a."Timestamp" <= GETDATE()
                                    GROUP BY``
                                    a.JourneyName, a.BonusName, a.Status, a."Timestamp", a.MID


                                    Total Count per day where Day_1 is today, Day_2 is yesterday and so on.






                                    share|improve this answer


























                                      0












                                      0








                                      0






                                      I finally get the correct data for today and last 7 days. Please refer below query.



                                      SELECT 
                                      a.JourneyName,
                                      a.BonusName,
                                      a.Status,
                                      a."Timestamp",
                                      a.MID,
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 0 THEN 1 ELSE NULL END) as "Day_1",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 1 THEN 1 ELSE NULL END) as "Day_2",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 2 THEN 1 ELSE NULL END) as "Day_3",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 3 THEN 1 ELSE NULL END) as "Day_4",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 4 THEN 1 ELSE NULL END) as "Day_5",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 5 THEN 1 ELSE NULL END) as "Day_6",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 6 THEN 1 ELSE NULL END) as "Day_7"
                                      FROM
                                      TableName a
                                      WHERE
                                      a."Timestamp" >= DATEADD(DD, -7, GETDATE())
                                      AND a."Timestamp" <= GETDATE()
                                      GROUP BY``
                                      a.JourneyName, a.BonusName, a.Status, a."Timestamp", a.MID


                                      Total Count per day where Day_1 is today, Day_2 is yesterday and so on.






                                      share|improve this answer














                                      I finally get the correct data for today and last 7 days. Please refer below query.



                                      SELECT 
                                      a.JourneyName,
                                      a.BonusName,
                                      a.Status,
                                      a."Timestamp",
                                      a.MID,
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 0 THEN 1 ELSE NULL END) as "Day_1",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 1 THEN 1 ELSE NULL END) as "Day_2",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 2 THEN 1 ELSE NULL END) as "Day_3",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 3 THEN 1 ELSE NULL END) as "Day_4",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 4 THEN 1 ELSE NULL END) as "Day_5",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 5 THEN 1 ELSE NULL END) as "Day_6",
                                      COUNT(CASE WHEN DATEDIFF(DD, a."Timestamp", GETDATE()) = 6 THEN 1 ELSE NULL END) as "Day_7"
                                      FROM
                                      TableName a
                                      WHERE
                                      a."Timestamp" >= DATEADD(DD, -7, GETDATE())
                                      AND a."Timestamp" <= GETDATE()
                                      GROUP BY``
                                      a.JourneyName, a.BonusName, a.Status, a."Timestamp", a.MID


                                      Total Count per day where Day_1 is today, Day_2 is yesterday and so on.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Nov 13 '18 at 6:34









                                      Thilina Nakkawita

                                      789927




                                      789927










                                      answered Nov 13 '18 at 5:45









                                      CAR

                                      13




                                      13






























                                          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%2f52695588%2fsql-get-the-total-count-of-registered-user-in-day-by-day%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

                                          Bressuire

                                          Vorschmack

                                          Quarantine