Problem with sum( ) over (partion by)

  • GSquared (5/5/2009)


    Lynn Pettis (5/5/2009)


    I'm thinking that SalesOrder and ReceiptNumber should be reversed allowing SalesOrder to be duplicated. Two receipts for each order. If you make the ReceiptNumber the PRIMARY KEY instead, then you could have order number 1 and 2 twice as originally posted.

    Not sure, I could be wrong.

    I thought of that too. Also wasn't sure, which is why I asked about it as a test harness.

    Agreed, need the OP to confirm/correct any assumptions we may have made before doing anything.

  • Hello guys, first of all thanks all for the help.

    In no way was I trying to yell at you I was posting from my laptop and disregarded caplocks (Funny how text can be seemed as yelling).

    Anyways I have found the solution,and the reason why the syntax was wrong is because I posted it from my house not work and had nowhere to test it.

    I'm running these queries straight from SAP, so I have no way to test it unless I'm at work.

    The solution i came with was to use a subquery where I select the sum of the quantity received and I subtract that from the open quantity.

    At work I manage inventory, however I started to mess with the query manager in sap and started to learn it ( I know java and C++), my manager decided to give me some queries to fix or make better and that's what I been doing. Overall I was able to fix them by googling and learning about sql as I went, however this problem was just killing me.

    Anyways thanks everybody for the help, hopefully you'll understand my situation and I apologize for any inconvenience.

    By the way today I learned that "" does not work if null , for which you need to include or is null.

  • slins4ever (5/5/2009)


    Hello guys, first of all thanks all for the help.

    In no way was I trying to yell at you I was posting from my laptop and disregarded caplocks (Funny how text can be seemed as yelling).

    Anyways I have found the solution,and the reason why the syntax was wrong is because I posted it from my house not work and had nowhere to test it.

    I'm running these queries straight from SAP, so I have no way to test it unless I'm at work.

    The solution i came with was to use a subquery where I select the sum of the quantity received and I subtract that from the open quantity.

    At work I manage inventory, however I started to mess with the query manager in sap and started to learn it ( I know java and C++), my manager decided to give me some queries to fix or make better and that's what I been doing. Overall I was able to fix them by googling and learning about sql as I went, however this problem was just killing me.

    Anyways thanks everybody for the help, hopefully you'll understand my situation and I apologize for any inconvenience.

    By the way today I learned that "" does not work if null , for which you need to include or is null.

    Etiquette says that since you asked for help that you should post your solution, even though you came up with it yourself. Someone else may have a similar issue, and this could help them.

  • True on the "is null" thing. That's an important one.

    On the sub-query, it sounds like you may have come up with the classic "triangular join" that gives running total type enumerations. If so, make sure you test your solution on large numbers of rows as well as small numbers of rows. Triangular joins work really, really well on very small tables, but they get exponentially slower as the number of rows increases. Can't be sure that's what you're talking about, because I haven't seen the code, but it's what it sounds like.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Yes I will post the solution tomorrow from work.

    And i don't necessarily have a running total, All I did was sum the total quantity of items received and subtracted from the open quantity, within the sub-query I had where statements to separate it by each sales order and itemcode.

Viewing 5 posts - 16 through 20 (of 20 total)

You must be logged in to reply to this topic. Login to reply