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. Simple (?) SQL Question

Simple (?) SQL Question

Scheduled Pinned Locked Moved Database
databasequestionhelp
4 Posts 2 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.
  • I Offline
    I Offline
    ISIS55
    wrote on last edited by
    #1

    Hey guys. Got a little question I could use some help. Suppose I have a table with 2 fields : Date and Ammount. I need to write a query that displays each date and the sum of ammounts to that date. I got a bit messed up with it... Isaac

    C 1 Reply Last reply
    0
    • I ISIS55

      Hey guys. Got a little question I could use some help. Suppose I have a table with 2 fields : Date and Ammount. I need to write a query that displays each date and the sum of ammounts to that date. I got a bit messed up with it... Isaac

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You could try joining the table onto itself

      SELECT d.[Date], SUM(a.Amount)
      FROM MyTable AS d
      INNER JOIN MyTable AS a ON a.[Date] <= d.[Date]


      "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

      I 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You could try joining the table onto itself

        SELECT d.[Date], SUM(a.Amount)
        FROM MyTable AS d
        INNER JOIN MyTable AS a ON a.[Date] <= d.[Date]


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        I Offline
        I Offline
        ISIS55
        wrote on last edited by
        #3

        Well you forgot the GROUP BY d.[Date] but it's genious none the less! Thanks a lot! Isaac

        C 1 Reply Last reply
        0
        • I ISIS55

          Well you forgot the GROUP BY d.[Date] but it's genious none the less! Thanks a lot! Isaac

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Well, I guess that happens from time to time when I type directly into Code Project rather than conduct a test first. Which is a good thing to learn: Always test code before releasing it. :-D


          "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

          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