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. which records are included in the sum

which records are included in the sum

Scheduled Pinned Locked Moved Database
databasequestion
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.
  • P Offline
    P Offline
    prithaa
    wrote on last edited by
    #1

    Hello, I have the following sql SELECT stocksymbol,tradedate, sum(qty ) FROM TradingTransactions where stocksymbol="HINDALCO" group by stocksymbol,tradedate having sum(qty)>1000 In the above query I get the SUM of qty but how do I know which records or record Nos were selected. Thanks Pritha

    J 1 Reply Last reply
    0
    • P prithaa

      Hello, I have the following sql SELECT stocksymbol,tradedate, sum(qty ) FROM TradingTransactions where stocksymbol="HINDALCO" group by stocksymbol,tradedate having sum(qty)>1000 In the above query I get the SUM of qty but how do I know which records or record Nos were selected. Thanks Pritha

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #2

      Just look at the where and having clauses. It is very exact actually. If you want to see which records were used, just run the query without the where and having clauses, and without the sum function, export the whole thing to Excel, and perform the same logic there, using subtotals and auto filters.

      My advice is free, and you may get what you paid for.

      P 1 Reply Last reply
      0
      • J Johan Hakkesteegt

        Just look at the where and having clauses. It is very exact actually. If you want to see which records were used, just run the query without the where and having clauses, and without the sum function, export the whole thing to Excel, and perform the same logic there, using subtotals and auto filters.

        My advice is free, and you may get what you paid for.

        P Offline
        P Offline
        prithaa
        wrote on last edited by
        #3

        thanks for your reply So do you mean to say that I cant know which records were included in the function through SQL in my database .And will have to go to Excel to find the same. Pritha

        J 1 Reply Last reply
        0
        • P prithaa

          thanks for your reply So do you mean to say that I cant know which records were included in the function through SQL in my database .And will have to go to Excel to find the same. Pritha

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          I think that maybe I do not understand your question. The where clause determine which records are included and the having clause determines that you don't want to see any dates which' records do not add up to (at least) 1000. That is simple and clear logic. So if you suspect that this query is not giving you the desired result, you can use Excel as a tool to check the outcome, and visually see each single record.

          My advice is free, and you may get what you paid for.

          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