Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to sum consecutive in number of day

How to sum consecutive in number of day

Scheduled Pinned Locked Moved Database
databasetutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hmanhha
    wrote on last edited by
    #1

    Hi All. I have a table in Microsoft SQL Database like that. date,UserID,number_of_product, number_of_sale Every day User sale number of product. Now I Want to count consecutive for each user, each product, and each day the total number of sale in number of day (for example 7 days) Thanks

    L J 2 Replies Last reply
    0
    • H hmanhha

      Hi All. I have a table in Microsoft SQL Database like that. date,UserID,number_of_product, number_of_sale Every day User sale number of product. Now I Want to count consecutive for each user, each product, and each day the total number of sale in number of day (for example 7 days) Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See SQL COUNT() Function[^] and SQL BETWEEN Operator[^].

      H 1 Reply Last reply
      0
      • L Lost User

        See SQL COUNT() Function[^] and SQL BETWEEN Operator[^].

        H Offline
        H Offline
        hmanhha
        wrote on last edited by
        #3

        The Data like that of course there is more ID ID1,14/04/2016, 5 ID1,13/04/2016, 2 ID1,11/04/2016, 1 ID1,10/04/2016, 4 ID1,08/04/2016, 7 So the Result like that. ID1, 14/04, 19 (19=5+2+1+4+7) ID1, 13/04, 14 (2+1+4+7) ID1, 11/04, 12 (1+4+7) ID1, 10/04, 11 (4+7) ID1, 08/04, 7

        L 1 Reply Last reply
        0
        • H hmanhha

          The Data like that of course there is more ID ID1,14/04/2016, 5 ID1,13/04/2016, 2 ID1,11/04/2016, 1 ID1,10/04/2016, 4 ID1,08/04/2016, 7 So the Result like that. ID1, 14/04, 19 (19=5+2+1+4+7) ID1, 13/04, 14 (2+1+4+7) ID1, 11/04, 12 (1+4+7) ID1, 10/04, 11 (4+7) ID1, 08/04, 7

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I gave you links to the command and option you need. Use those to construct a query (or multiple queries) to select the records you want.

          1 Reply Last reply
          0
          • H hmanhha

            Hi All. I have a table in Microsoft SQL Database like that. date,UserID,number_of_product, number_of_sale Every day User sale number of product. Now I Want to count consecutive for each user, each product, and each day the total number of sale in number of day (for example 7 days) Thanks

            J Offline
            J Offline
            John C Rayan
            wrote on last edited by
            #5

            Familiarise yourself with aggregate functions in SQL. GroupBy etc. If you learn them , what you are trying to do is simple for you.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups