Partition by error

  • Hi guys,

    So i am trying to display the percent of amount_paid by each item_name, divided by amount_paid of all items

    Note that i dont wanna GROUP BY it. I need to display each of the items the number of times it has been ordered

    So here is my query : 

    Select item_name , Sum(amount_paid) over (partition by item_name) / SUM(amount_paid) From order_items

    and i am getting the following error : 
    Incorrect syntax near '/'.

    Any suggestions?
    Thanks

  • Unless there's more to what you're running than you're showing us, that error shouldn't occur with that query.

    You WOULD get an error saying that item_name is invalid in the select list, since you're using an aggregate without OVER.

    On your second SUM(amount_paid), change it to SUM(amount_paid) OVER ().

    That will avoid that particular problem. However, since you're getting an error that isn't explained by the code you've shown, it's hard to say what else might be the problem.

    Cheers!

  • does this work?

       Select item_name
             , Sum(amount_paid) over (partition by item_name) / SUM(amount_paid) Over() s
       From order_items;

  • Joe Torre - Tuesday, June 20, 2017 1:03 PM

    does this work?

    Yep !

    Thanks Joe

    I don't know what over() s means, but it works!

Viewing 4 posts - 1 through 3 (of 3 total)

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